我正在建立一个学生管理系统,我有三个用户。
管理员,学生和超级管理员。
我通过过滤器处理授权。当用户登录时,根据他的角色重定向它,例如,如果用户是学生将用户重定向到学生页面
但问题在于SuperAdmin
在FilterBean中
x <- rnorm(20, sd=3)
d <- diff(x)
plot(x)
for (i in which(d>3)) {
lines(c(i,i+1), x[i:(i+1)])
text(i+.5, mean(x[i:(i+1)]), round(d[i],1), pos=2)
}
如果我将import java.io.IOException;
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.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author Sikandar
*/
public class FilterBean implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
//HttpSession session = req.getSession();
HttpSession session = req.getSession();
String userName = (String) session.getAttribute("userName");
String role = (String) session.getAttribute("role");
System.out.println("role in Filter out side condition " +role);
String url = req.getRequestURI();
if (session == null || userName == null) {
System.out.println("The role is if session == null "+role);
if (url.indexOf("admin.xhtml") >= 0 || url.indexOf("student.xhtml") >= 0 || url.indexOf("superadmin.xhtml") >= 0) {
resp.sendRedirect(req.getServletContext().getContextPath()+"/login.xhtml");
} else {
chain.doFilter(request, response);
}
} else {
if(role.equals("admin") && (url.indexOf("login.xhtml") >= 0 || url.indexOf("superadmin.xhtml") >= 0 || url.indexOf("student.xhtml") >= 0)) {
resp.sendRedirect(req.getServletContext().getContextPath()+"/admin.xhtml");
} else if (role.equals("super") && (url.indexOf("login.xhtml") >= 0 || url.indexOf("student.xhtml") >=0)) {
System.out.println("role == super "+url.indexOf("admin.xhtml"));
resp.sendRedirect(req.getServletContext().getContextPath()+"/superadmin.xhtml");
} else if (role.equals("student") && (url.indexOf("login.xhtml") >= 0 || url.indexOf("admin.xhtml") >=0 || url.indexOf("superadmin.xhtml") >= 0)) {
resp.sendRedirect(req.getServletContext().getContextPath()+"/student.xhtml");
}
else {
chain.doFilter(request, response);
}
}
}
@Override
public void destroy() {
}
}
else if (role.equals("super") && (url.indexOf("login.xhtml") >= 0 || url.indexOf("student.xhtml") >=0)) {
System.out.println("role == super "+url.indexOf("admin.xhtml"));
resp.sendRedirect(req.getServletContext().getContextPath()+"/superadmin.xhtml");
置于此状态,则表示页面中有更多重定向。
答案 0 :(得分:0)
url.indexOf("superadmin.xhtml");
和url.indexOf("admin.xhtml");
两者都包含 admin.xhtml 作为后缀,这可能是一个问题,尝试将 superadmin.xhtml 重命名为 adminsuper.xhtml