下面是过滤器代码及配置,根本就不会执行过滤器里的代码。请大家帮忙看下哪里出了问题
public class LoginValidateFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
//判断用户是否登录(即判断session中是否存在名为user的对象),如果没有登录,将用户的浏览器重定向到/user/logon.do
HttpServletRequest httpRequest = (HttpServletRequest) req;
Buyer buyer = WebUtil.getBuyer(httpRequest);
if(buyer==null){
HttpServletResponse httpResponse = (HttpServletResponse)res;
httpResponse.sendRedirect("user_logon.action");
return; //这句要加上,否则这个过滤器不起作用
}
chain.doFilter(req, res);
}}web.xml配置如下 <!-- Struts过滤器,符合请求格式则纳入框架处理 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- 该Filter用于验证用户是否已经登录,没有未登录,即重定向到登录界面 -->
<filter>
<filter-name>loginValidateFilter</filter-name>
<filter-class>
com.lh.web.filter.LoginValidateFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>loginValidateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
解决方案 »
- structs2编程需要加哪些包?或者说myeclipse建web应用的时候怎么才能有structs2的选项
- 我的项目ssh2框架,加了rulrewrite包和一些配置,没有效果,帮忙看看,谢谢了
- JS中使用javabean
- 请教个获取复选框表单中数据的问题
- 关于文件上传,基于Apache Fileupload
- base64编码啥用?
- 问大家一个问题啊!!!!!!!!!!!!!!!
- 急!求救!采用struts,怎么才能同时更新十几条记录的内容呢?
- Servlet 检索文件为什么 比 php慢这么多
- 急救啊!谁有关于java.sql库的对像及方法的参考手册呀?
- apache上传组件报磁盘空间不足问题
- web dynpo for JAVA 开发的系统,我用IE打开后,点击按钮不能操作
<!-- 该Filter用于验证用户是否已经登录,没有未登录,即重定向到登录界面 -->
<filter>
<filter-name>loginValidateFilter</filter-name>
<filter-class>
com.lh.web.filter.LoginValidateFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>loginValidateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- Struts过滤器,符合请求格式则纳入框架处理 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<action name="DeliverInfo_*" method="{1}" class="com.lh.web.action.shopping.DeliverInfoAction">
<result name="deliver">/WEB-INF/page/shopping/deliverInfo.jsp</result>
</action>
<!-- 用户管理 -->
<action name="user_*" class="com.lh.web.action.user.BuyerManageAction" method="{1}">
<result name="regUI">/WEB-INF/page/user/userReg.jsp</result>
<result name="reg" type="redirect">user_regUI.action</result>
<result name="logon" >/WEB-INF/page/user/logon.jsp</result>
</action>
<filter-name>loginValidateFilter</filter-name>
<filter-class>
com.lh.web.filter.LoginValidateFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>loginValidateFilter</filter-name>
<url-pattern>user*</url-pattern>
</filter-mapping>