开发者

Change the class loader of the JSP servlet (Jasper)

What I want to achieve, is to proxy the request URI and render a different JSP file depending on some condition in the request users session.

I.e.

userA -> request: /{container}/index.jsp -> return: {viewA}/index.jsp

userB -> request: /{container}/index.jsp -> return: {viewB}/index.jsp

Servlet filters don't have enough control to do this sort of thing. What I'd imagine would work would be to override the URLClassLoader of the JSPServlet so that I can searc开发者_运维技巧h for the file [in a custom classloader] to be compiled. Is this possible, or is there another way?

I read something that relates to what I'm trying to acheive here: http://www.softwaresummit.com/2003/speakers/BergmanTomcat.pdf pp 10, however, it doesn't really appear to work (extending HttpJspBase doesn't give you anything).

I've tried to illustrate the flow in this [rather poor] image:

http://80.68.91.73/pageflow.png

I'm more looking for a steer in the right direction rather than a complete solution. The problem is, I can't find the right keywords to find what I'm looking for!

Thanks!

John


This is not exactly what you asked for, but have you considered having only one index.jsp and use the forward-tag to forward the request to different sub-pages?

<% if(session.someCondition) { %>
  <jsp:forward page="index-version1.jsp"/>
<% } else { %>
  <jsp:forward page="index-version2.jsp"/>
<% } %>

You may also forward the request from a servlet filter using something like this:

FilterConfig filterConfig;

public void init(FilterConfig filterConfig) {
    this.filterConfig = filterConfig;
}

public void doFilter( ..) {

    filterConfig.getServletContext().getRequestDispatcher(<insert path to correct version of your page here>).forward(request, response);

}

If you don't want the jsp-pages to be accessible directly, you may store them in different sub-directories below WEB-INF. That way, you may forward to them, but they can't be reached directly from the web.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜