Recently, when using struts2 for a project, you need to intercept JSP to verify whether it has been logged in. However, the filter chain of struts2 can only filter action. Later, we can add the javax. servlet. Filter Implementation class filters in web. xml to Filter JSP. See the code Filter Implementation class [java] <span style = "font-size: 18px;"> package com. common; import java. io. IOException; import javax. servlet. filter; import javax. servlet. filterChain; import javax. servlet. filterConfig; import javax. servlet. servletException; import javax. servlet. servletRequest; import javax. servlet. servletResponse; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import Javax. servlet. http. httpServletResponse; public class LoginFilter extends HttpServlet implements Filter {private static final long serialVersionUID = 1L; @ Override public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, servletException {HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) respo Neuron; String path = req. getContextPath (); String indexPath = req. getScheme () + ": //" + req. getServerName () + ":" + req. getServerPort () + path + "/pages/login. jsp "; if (req. getRequestURI (). endsWith ("login. jsp ") {chain. doFilter (request, response); return;} Object loginuser = req. getSession (). getAttribute ("<strong> <span style =" color: # ff0000; "> loginSession </span> </strong>"); if (loginuser = null) {res. sendRedir Ect (indexPath); return;} chain. doFilter (request, response) ;}@ Override public void init (FilterConfig arg0) throws ServletException {// TODO Auto-generated method stub }</span> logon method: [java] <span style = "font-size: 18px;"> public String login () {Login login = new Login ();//....... verify the logon information ActionContext ctx = ActionContext. getContext (); Map <String, Object> session = ctx. getSession (); session. put ("<Strong> <span style =" color: # ff0000; "> loginSession </span> </strong>", login); return "success ";} </span> web. xml configuration [html] <filter> <filter-name> setlog </filter-name> <filter-class> com. common. loginFilter </filter-class> </filter> <filter-mapping> <filter-name> setlog </filter-name> <url-pattern>/pages/home. jsp </url-pattern> <url-pattern>/pages/channel/* </url-pattern> <url-pattern>/pages/content/* </url-pa Ttern> <url-pattern>/pages/product/* </url-pattern> <url-pattern>/pages/vodtask/* </url-pattern> </filter- mapping> note, if the framework is used on the page, the session may be timed out and displayed on the logon page. The logon page is displayed on a subpage of the framework. To solve this problem, add the following code to the logon page. [Html] <span style = "font-size: 18px;"> <script language = "javascript"> if (top! = Window) top. location. href = window. location. href; </script> </span>