java重定向后登录页显示空白页面,报错多次重定向 20
Subjectsub=SecurityUtils.getSubject();if(!sub.isAuthenticated()){//取得JSON传值ActionCont...
Subject sub = SecurityUtils.getSubject();
if(!sub.isAuthenticated()){
// 取得JSON传值
ActionContext actionContext = ActionContext.getActionContext();
HttpServletRequest reqs = actionContext.getHttpServletRequest();
HttpServletResponse resp = actionContext.getHttpServletResponse();
// 重定向
String path = reqs.getContextPath();
String basePath = reqs.getScheme() + "://"+ reqs.getServerName() + ":" + reqs.getServerPort()+ path + "/";
resp.sendRedirect(basePath);
return;
} 展开
if(!sub.isAuthenticated()){
// 取得JSON传值
ActionContext actionContext = ActionContext.getActionContext();
HttpServletRequest reqs = actionContext.getHttpServletRequest();
HttpServletResponse resp = actionContext.getHttpServletResponse();
// 重定向
String path = reqs.getContextPath();
String basePath = reqs.getScheme() + "://"+ reqs.getServerName() + ":" + reqs.getServerPort()+ path + "/";
resp.sendRedirect(basePath);
return;
} 展开
1个回答
2017-10-31 · 知道合伙人互联网行家
关注
展开全部
请回去搞清楚什么是重定向什么是转发!!
解析器不行,用我的
package main.jsp.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import main.bean.userbean.UserBean;
/**
* @ClassName :CheckFilter
* @Description :验证用户登录状态,过滤非法登录
* @author :gaoshou
* @date :2013-8-14
*/
public class CheckFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @descriptiion :验证用户登录状态
*
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String uri = ((HttpServletRequest) request).getRequestURI();
List<String> urilist=new ArrayList<String>();
urilist.add("/UserLoginReg/UserManageServlet");
urilist.add("/UserLoginReg/FindUserServlet");
urilist.add("/UserLoginReg/DoUpdateServlet");
urilist.add("/UserLoginReg/AutherUpServlet");
urilist.add("/UserLoginReg/DoAddServlet");
if(urilist.contains(uri)==true){
HttpSession session = req.getSession(true);
// 从session里取的用户名信息
UserBean user = (UserBean) session.getAttribute("userall");
// 判断如果没有取到用户信息,就跳转到登陆页面
if (user == null) {
// 跳转到登陆页面
request.setAttribute("info", "请先登录");
req.getRequestDispatcher("WEB-INF/jsp/login.jsp").forward(request,
response);
} else {
// 已经登陆,继续此次请求
chain.doFilter(request, response);
}
}else {
// 已经登陆,继续此次请求
chain.doFilter(request, response);
}
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
解析器不行,用我的
package main.jsp.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import main.bean.userbean.UserBean;
/**
* @ClassName :CheckFilter
* @Description :验证用户登录状态,过滤非法登录
* @author :gaoshou
* @date :2013-8-14
*/
public class CheckFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @descriptiion :验证用户登录状态
*
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String uri = ((HttpServletRequest) request).getRequestURI();
List<String> urilist=new ArrayList<String>();
urilist.add("/UserLoginReg/UserManageServlet");
urilist.add("/UserLoginReg/FindUserServlet");
urilist.add("/UserLoginReg/DoUpdateServlet");
urilist.add("/UserLoginReg/AutherUpServlet");
urilist.add("/UserLoginReg/DoAddServlet");
if(urilist.contains(uri)==true){
HttpSession session = req.getSession(true);
// 从session里取的用户名信息
UserBean user = (UserBean) session.getAttribute("userall");
// 判断如果没有取到用户信息,就跳转到登陆页面
if (user == null) {
// 跳转到登陆页面
request.setAttribute("info", "请先登录");
req.getRequestDispatcher("WEB-INF/jsp/login.jsp").forward(request,
response);
} else {
// 已经登陆,继续此次请求
chain.doFilter(request, response);
}
}else {
// 已经登陆,继续此次请求
chain.doFilter(request, response);
}
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询