action实现注销问题

sucab 2012-02-22 01:19:38
struts2中,action方法里获取到的map类型的session,并把值已经存入。现在要实现注销logout,执行下面代码后:
///////////////////////////////////注销方法
public class Logout extends ActionSupport {

private ActionContext context;
private Map session;
//private HttpSession session;

public String logout() throws Exception {
this.context = ActionContext.getContext();
///this.session = (HttpSession)this.context.getSession();不能强转为httpsession
this.session = (Map)this.context.getSession();
/* session.clear();
System.out.println(session.isEmpty());*/
session.remove("username");
System.out.println(session.isEmpty());
//session.removeAttribute("username");
//session.invalidate();

return "logout";
}

}
//////////////////////////////////过滤器
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpSession session=((HttpServletRequest) request).getSession(true);
if(session.getAttribute("username")== null){
System.out.println("你还未登陆");
//String url = "http://localhost:8888/Test_Online/admin/login.jsp";
String url = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/test_struts2/login.jsp";
//String url = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + request.getContextPath() + LoginRightFilter.FORWARD;
StringBuffer scriptString=new StringBuffer();
scriptString.append(" <script>\n\r");
scriptString.append("alert(\"你还未登陆\")");
scriptString.append("self.top.location.href=\""+url+"\"\n\r");
scriptString.append(" </script>\n\r");
response.getOutputStream().print(scriptString.toString());
//System.out.println(session.getAttribute("adminrole"));
}else{

chain.doFilter(request, response);
}

}
我又进入一个新的页面(已设置过滤器),报的错是:
java.io.CharConversionException: Not an ISO 8859-1 character: 你
at javax.servlet.ServletOutputStream.print(ServletOutputStream.java:89)
at filter.LegalUser.doFilter(LegalUser.java:34)
at org.apache.catalina.core.ApplicationFilterChain
好像session里有记录,还是有cookies的?没清除网页自动记忆的用户名“你”,(我曾经输过的)不懂???
...全文
90 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellobbboy 2012-02-22
  • 打赏
  • 举报
回复
编码的事,同楼上
  • 打赏
  • 举报
回复
response.setContentType("text/html;charset=utf-8");
response.getOutputStream().write(scriptString.toString().getBytes("UTF-8"));
化石 2012-02-22
  • 打赏
  • 举报
回复
让session失效呢
不就注销了吗

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧