我struts.xml
有两个动作如下
<action name="dologincheck" class="com.platinum.uac.biz.LoginAction" method="doLogin">
<result name="success" type="tiles">Homepage</result>
<!-- <result name="success">/Profile/view/ViewProfile1.jsp</result>-->
<result name="none">/Profile/add/Failure.jsp</result>
<result name="mail">/Profile/add/EmailAuthentication.jsp</result>
</action>
<action name="newuseraction" class="com.platinum.uac.biz.NewUserAction" method="newuser">
<result name="success" >/Profile/add/ProfileDetails.jsp</result>
<result name="error" >/index.jsp</result>
</action>
我需要从方法中调用一个 action( dologincheck
) 。doFilter
我被困在这里,因为我不知道如何从doFilter
方法调用动作
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws
IOException, ServletException {
try {
System.out.println("this is do filter before the jsp page");
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = ((HttpServletResponse) res);
HttpSession session = request.getSession(true);
String username, password;
Cookie[] cookies;
LoginPojo user = (LoginPojo) session.getAttribute("username");
if (user == null) {
cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
username = getCookieValue(cookies, "username");
password = getCookieValue(cookies, "password");
System.out.println(username);
System.out.println(password);
if (username != null && password != null) {
LoginPojo pojo = new LoginPojo(username, password);
results = dao.Login(pojo);
session.setAttribute("userName", user); // usersession?
request.getRequestDispatcher("dologincheck").forward(request,
response);
} else {
request.getRequestDispatcher("/index.jsp").forward(request,
response);
}
} else {
request.getRequestDispatcher("/index.jsp").forward(request,
response);
}
}
} catch (Exception e) {
}
chain.doFilter(req, res);
//throw new UnsupportedOperationException("Not supported yet.");
}
我的过滤器部分web.xml
是
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AutomaticLogin</filter-name>
<filter-class>com.platinum.uac.biz.AutomaticLogin</filter-class>
</filter>
<filter-mapping>
<filter-name>AutomaticLogin</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.action</url-pattern>
<servlet-name>action</servlet-name>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>