web module servletpath

3 views
Skip to first unread message

jokoul webster

unread,
Apr 10, 2010, 1:50:06 PM4/10/10
to impala...@googlegroups.com
Hi Phil:
       If I wanna write some jsps in WebModule1(Which is as same level as WebModule2) and wanna invoke some atcions which are in WebModule2,how to set the link in jsp? For Example,
       1:if the jsp is embedded in Host module,then "<a href="WebModule2/action">xxx</a>" is right,I have tried it successfully;
       2:if the jsp is within the WebModule2,then "<a href="../WebModule2/action">xxx</a>" is right,I have tried it successfully;
       3:if the jsp is within the WebModule1,then neither "<a href="WebModule2/action">xxx</a>"  nor "<a href="../WebModule2/action">xxx</a>" is right,and if the value is"<a href="${request.contextPath}/WebModule2/action">xxx</a>" ,the request.contextPath is empty,how to handle it?
      
Thanks
 
JK.Webster

Phil Zoio

unread,
Apr 12, 2010, 6:34:15 AM4/12/10
to impala...@googlegroups.com
Jokoul

You should be able to refer to the JSP using a relative URL from any
other page. It is just a question of making sure that the relative URL
reflects the relative locations of the referring action/page, and the
target page.

Regards,
Phil

Phil Zoio

unread,
Apr 15, 2010, 5:41:47 PM4/15/10
to impala-users
I've now added an additional option into the "to-module" attribute,
which I think makes things a bit easier and more intuitive when
dealing with JSPs.

In the web frameworks example, there is now a JSP-only module which
has the following Spring definition:

<web:mapping>
<web:to-module prefix = "/jsp" setContextPath="true"/>
<web:to-handler extension = "jsp" servletName="jspServlet"/>
<web:to-handler extension = "gif" servletName="jspResources"/>
<web:to-handler extension = "css" servletName="jspResources"/>
</web:mapping>

<web:servlet id = "jspResources"
servletClass = "org.impalaframework.web.servlet.ResourceServlet"/>

<web:jsp-servlet id="jspServlet"/>

The setContextPath attribute means that requests which are mapped to
the module using the '/jsp' prefix will have the context path
(HttpServletRequest.getContextPath()) equal to the application path
plus /jsp (e.g. /webframeworks/jsp).

In this case, the URL:

http://localhost:8080/webframeworks-host/jsp/hello.jsp

is mapped to hello.jsp, which is in the 'default' package in
webframeworks-jsp module's classpath.

For resources, this works similarly. The stylesheet

http://localhost:8080/webframeworks-host/jsp/css/style.css

is mapped to style.css, contained within the 'css' package.

Phil

Reply all
Reply to author
Forward
0 new messages