大家好,欢迎来到IT知识分享网。
拦截器类
package com.csair.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.http.HttpRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.Interceptor;
@SuppressWarnings("serial")
public class StrutsInterceptor implements Interceptor {
public void destroy() {
System.out.println("StrutsInterceptor destroy");
}
public void init() {
System.out.println("StrutsInterceptor init");
}
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("StrutsInterceptor intercept");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
String host = request.getRemoteHost();
System.out.println("host:"+host);
return invocation.invoke();
}
}
struts.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="utf-8" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts2.ObjectFactory" value="Spring" />
<constant name="struts.custom.i18n.resources" value="application" />
<package name="default" extends="struts-default" namespace="/">
<interceptors>
<interceptor name="strutsInterceptor" class="com.csair.interceptor.StrutsInterceptor"/>
<interceptor-stack name="intercetor">
<interceptor-ref name="store"/>
<interceptor-ref name="paramsPrepareParamsStack" />
<interceptor-ref name="strutsInterceptor"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="intercetor"/>
<action name="login" class="com.csair.web.strutsDemo" method="login">
<result name="login">/login.jsp</result>
</action>
<action name="reportDetail" class="com.csair.web.ReportDetailAction" method="reportDetail">
<result name="reportDetail">/reportDetail.jsp</result>
</action>
</package>
</struts>
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/24847.html