当前位置:编程学习 > JAVA >>

webwork框架的问题。

判断是否登录的java类
package com.koal.fmsl.util;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.koal.j2ee.compenents.privilege.hibernate.pojo.PriUser;
import com.koal.j2ee.util.webwork.ValidateUserInterceptor;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.AroundInterceptor;
import com.opensymphony.xwork.interceptor.Interceptor;

public class SessionFilter implements Interceptor{
private final static Log log = LogFactory.getLog(ValidateUserInterceptor.class);
public void destroy() {
// TODO Auto-generated method stub

}
public void init() {
// TODO Auto-generated method stub

}
public String intercept(ActionInvocation arg0) throws Exception {
log.info("我进来了!!!!!!!!!!!!");
System.out.println("我进来了!!!!!!!!!!!!");
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session =  request.getSession(); 
response.setCharacterEncoding("GBK");
ServletContext application = session.getServletContext();
  PriUser  loginuser   =(PriUser)session.getAttribute("UserToken"); 
if(loginuser   ==   null) { 
response.getWriter().print("<script language='javascript'>window.location='/logoffServlet';</script>");//返回登陆
log.info("转向重新登录页面.....................");
}else{//判断sessionID是不存在LIST,不存在执行session.invalidate(); 
System.out.println("我进来了!!!!!!!!!!!!");
List list2 =(List)application.getAttribute(loginuser.getAccount());
for(int i=0;i<list2.size();i++) {
String sessionId=(String)list2.get(i);
if(!session.getId().equals(sessionId)) {
session.invalidate();
response.getWriter().print("<script>alert('此用户在另一地点登录');window.location='/logoffServlet';</script>");//返回登陆
log.info("转向重新登录页面.....................");
}
}

return invocation.invoke();
}
}
web.xml文件代码
<filter>
<filter-name>webwork</filter-name>
<filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>webwork</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
xwork.xml文件一段代码
<package name="drug" extends="webwork-default">
<interceptors>
<interceptor name="actionHandle" class="com.koal.j2ee.util.webwork.ProcessActionHandle" />
<interceptor name="session" class="com.koal.fmsl.util.SessionFilter"></interceptor>
      <interceptor-stack name="myinterceptors">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="session"/>
  </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="myinterceptors"/>

谁能帮我看一下为什么没有被拦截。或者谁能给我发一个xwork实例,谢谢了!邮箱:469088325@qq.com --------------------编程问答-------------------- 没人来关了 --------------------编程问答-------------------- <url-pattern>*</url-pattern>
改为/*试试
补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,