使用JSP,除了对管理页面的请求之外,如何将所有内容重定向到保留页面
我在这里使用谷歌应用程序引擎 在web.xml中,我将安全设置为:使用JSP,除了对管理页面的请求之外,如何将所有内容重定向到保留页面,jsp,Jsp,我在这里使用谷歌应用程序引擎 在web.xml中,我将安全设置为: <security-constraint> <web-resource-collection> <url-pattern>/admin/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name
<security-constraint>
<web-resource-collection>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
/管理员/*
管理
现在,我想通过使用servlet at/admin对数据存储的模式进行一些大的更改,同时将所有其他请求重定向到BeBackSoon.jsp之类的内容
有没有一种简单的方法可以使用web.xml实现这一点?您可以使用
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String contextPath = request.getContextPath();
if (request.getRequestURI().startsWith(contextPath + "/admin") {
chain.doFilter(req, res);
} else {
response.sendRedirect(contextPath + "/BeBackSoon.jsp");
}
}
将此映射到
/*
的URL模式。注意,如果在不同的路径后面有CSS/JS/images等静态资产,您希望在条件中包括对其公共路径的检查,如“/static”
,否则您的管理页面将没有正确的CSS/JS/images。您只需在进行更改后重新部署应用程序即可。也许我不理解你的问题?两个(很容易解决)问题:1)代码导致无限循环(检查请求是否针对contextPath+目的地。2)在GAE上,你还需要检查contextPath+“/_ah/”,以处理管理员登录。