java 后台主页面包含的子页面被过滤器检测到没有session而自动跳转到了登陆页面

2024-11-25 00:19:56
推荐回答(2个)
回答1:

你先把过滤器new出来,再调用不就好了

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=gbk");
PrintWriter out = response.getWriter();

String name = request.getParameter("username");
String password = request.getParameter("password");
HttpSession session = request.getSession();

if(name.equals("凯陵admain") && password.equals("admain")){

session.setAttribute("兄唤usertype", "admain");

Fileter f=new Fileter();
f.doFilter(request,response,chain);//反正羡孙凯你先把过滤器new出来,再调用不就好了,具体的属性看实际情况,我是手写代码,难免有错

}else{
out.print("用户页面");
}
}

回答2:

把session设置成整个网站的。。。。。。。。