开发者

With JSP, how do I redirect everything to a holding page, apart from requests for admin pages

I'm using google app engine here.

In web.xml I have security set up as so:

    <security-constraint>
      <web-resource-collection>
        <url-pattern>/admin/*</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name&开发者_运维问答gt;admin</role-name>
      </auth-constraint>
    </security-constraint>

Now I would like to makes some large changes to the schema of the datastore by using servlets at /admin, while redirecting all other requests to something like BeBackSoon.jsp

Is there a simple way to do this with web.xml?


You can use a filter for this.

@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");
    }
}

Map this on an URL pattern of /*. Note, if you have static assets like CSS/JS/images behind a different path, you'd like to include a check on their common path like "/static" in the condition, otherwise your admin pages will end up without proper CSS/JS/images.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜