struts2中怎样实现过滤jsp页面的过滤器
1个回答
展开全部
如下所示:
package test;
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;
public class LoginFilter implements Filter
{
public void destroy()
{
}
public void doFilter(ServletRequest req, ServletResponse rsp,
FilterChain chain) throws IOException, ServletException
{
chain.doFilter(req, rsp);
}
public void init(FilterConfig arg0) throws ServletException
{
}
}
在web.xml里面配置
<filter>
<filter-name>logFilter</filter-name>
<filter-class>test.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>logFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
package test;
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;
public class LoginFilter implements Filter
{
public void destroy()
{
}
public void doFilter(ServletRequest req, ServletResponse rsp,
FilterChain chain) throws IOException, ServletException
{
chain.doFilter(req, rsp);
}
public void init(FilterConfig arg0) throws ServletException
{
}
}
在web.xml里面配置
<filter>
<filter-name>logFilter</filter-name>
<filter-class>test.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>logFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询