开发者

Why can't I wrap the ServletRequest when trying to capture JSP output

I am trying to dispatch in a servlet request handler to the JSP processor and capture the content of it.

I am providing wrapper instances for the ServletRequest and ServletResponse, they implement the corresponding HTTPServletRequest/-Response interfaces, so they should be drop-in replacements. All methods are currently passed to the original Servlet Request object (I am planning to modify some of them soon). Addit开发者_如何转开发ionally I have introduced some new methods. (If you want to see the code: http://code.google.com/p/gloudy/source/browse/trunk/gloudyPortal/src/java/org/gloudy/gloudlet/impl/RenderResponseImpl.java)

The HttpServletResponse uses its own output streams to capture the output.

When I try to call

request.getRequestDispatcher("/WEB-INF/views/test.jsp").include(request, response);    

With my request and response wrappers the method returns and no content has been captured. When I tried to pass the original request object it worked! But that's not what I need in the long run...

request.getRequestDispatcher("/WEB-INF/views/test.jsp").include(request.getServletRequest(), response);

This works. getservletRequest() returns the original Request, given by the servlet container.

Does anyone know why this is not working with my wrappers?

Update: I am trying this on the google app engine dev environment, which uses the geronimo implementation for the servlet container IIRC


OK, found the problem...

I have replaced the attribute related functions with my own implementation. That was the reason that the jsp processor returned empty results (without any error message...)

So it's a bad idea to do this in your ServletRequest Wrappers if you want to use Request Dispatcher:

 private Map<String, Object> attributes = new HashMap<String, Object>();
 ...

 public Object getAttribute(String string) {
    return attributes.get(this);
  }

  public Enumeration<String> getAttributeNames() {
    return (Enumeration<String>) attributes.keySet();
  }

  public void setAttribute(String string, Object o) {
    attributes.put(string, o);
  }

  public void removeAttribute(String string) {
    attributes.remove(string);
  }

It works without these lines. Maybe this helps someone who tries similar things...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜