开发者

Request attributes across c:import contexts

I'm working on a jsp(test.jsp) in a web-app with a servlet context of /hello. I am doing the following:

<c:import url = "/other/altTest.jsp" context="/" />

It appears that request attributes available to test.jsp are unavailable to the imported jsp from the c:import (altTest.jsp), I suspect due to the context p开发者_StackOverflow中文版arameter. Could someone please explain the reason behind this as well as suggest an alternative method of importing that jsp where I could access request attributes?


The c:import fires under the covers a new and independent HTTP request. Even if the file was in the same context, it wouldn't have access to the same request as the parent JSP was opened with.

Your best bet is to pass the information as request parameter or maybe store as session attribute and then let the imported JSP remove it from the session. Still, this require that the different contexts share the same session --this is configureable at servletcontainer level, in for example Tomcat, set the emptySessionPath attribute to true in context.xml.

An alternative is to use a servlet instead wherein you can do ServletContext#getContext() to obtain the other servlet context (only if crossContext attribute is set to true in context.xml) and then obtain the RequestDispatcher and finally invoke the forward() on it. This isn't possible by JSP tags.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜