Which servlet would be used to support for css,image deployed within individual web modules

10 views
Skip to first unread message

jokoul webster

unread,
Mar 28, 2010, 3:04:45 AM3/28/10
to impala...@googlegroups.com
Hi Phil:
    Now Impala can support for JSPs deployed within individual web modules,yes,I can run it well,but how to support for other files e.g css,png,gif within individual web modules?
    I have tried but failed to display my images in jsp,my struts2 web module's context spring file is below:
============================================================
<web:mapping>
  <web:to-module prefix = "/struts2"/>
  <web:to-handler extension="jsp" servletName="mydemo-jsp"/>
  <web:to-handler extension="action" filterNames="mydemo-struts2"/>
  <web:to-handler extension = "css" servletName="mydemo-resources"/>
  <web:to-handler extension = "gif" servletName="mydemo-resources"/>
 </web:mapping>
 <web:filter id = "myStruts2Filter"
  delegatorFilterName = "mydemo-struts2"
  filterClass = "org.apache.struts2.dispatcher.FilterDispatcher"  >
 </web:filter>
 
 <bean id="mydemo-jsp" class="org.impalaframework.web.jsp.JspServletFactoryBean">
     <property name="servletName" value = "mydemo-jsp"/>
  </bean>
 
 <web:servlet id = "mydemo-resources"
        servletClass = "org.impalaframework.web.servlet.ResourceServlet"
        initParameters = "cacheTimeout=10"/>
......
============================================================
and my jsp is :
<img src="<%=request.getContextPath()%>/struts2/img/logo.gif"/>
============================================================
Thanks.
 
JK.Webster

Phil Zoio

unread,
Mar 29, 2010, 4:24:44 AM3/29/10
to impala...@googlegroups.com
Hi Jokoul

If you are mapping to Impala modules using the /* mapping in web.xml,
then the value for request.getPathInfo() will not be set by the web
container.

In this case, you will need to add the following to the web:to-module entry:

<web:to-module prefix = "/struts2" setServletPath="true"/>

In general, I would recommend you to use this configuration.

However, in doing so in the current example, this will probably affect
mappings within the application in your example, because the
request.getServletPath() in your example will be set to the prefix value
(ie /struts2). To stop this from happening, use

<web:to-module prefix = "/struts2" setServletPath="true" servletPath=""/>

I've tried this approach out in the URL mapping sample
(http://code.google.com/p/impala/wiki/SamplesURLMapping), to confirm
that it works.

Phil

jokoul webster

unread,
Mar 30, 2010, 10:42:49 AM3/30/10
to impala...@googlegroups.com

But if I use struts2,I can not set setServletPath="true".

Phil Zoio

unread,
Mar 30, 2010, 11:05:48 AM3/30/10
to impala...@googlegroups.com
See my previous reply:
... you will need to add the following to the web:to-module entry:


<web:to-module prefix = "/struts2" setServletPath="true"/>

In general, I would recommend you to use this configuration.

However, in doing so in the current example, this will probably affect
mappings within the application in your example, because the
request.getServletPath() in your example will be set to the prefix value
(ie /struts2). To stop this from happening, use

<web:to-module prefix = "/struts2" setServletPath="true" servletPath=""/>

I've tried this approach out in the URL mapping sample
(http://code.google.com/p/impala/wiki/SamplesURLMapping), to confirm
that it works.
In other words, you can either setServletPath="true", but will probably cause you to have to change internal mappings, or you can use the setServletPath="true" servletPath="" combination.

Phil

jokoul webster

unread,
Mar 30, 2010, 1:13:23 PM3/30/10
to impala...@googlegroups.com
Hi Phil,I do know what you mean,but I do not knwo what value I should set to "servletPath",my question is:
1: the current module name is "mydemo-struts2",
2: the module prefix is "struts2",
3: the struts2 package is "tutorial"
4:the image code is <img src="img/logo.gif"/>
5: the web mapping is <web:to-module prefix = "/struts2"  setServletPath="true" servletPath=""/>
in that case,when run it,the image logo.gif can not be displayed in jsp,and the source code is http://localhost:8080/mydemo-host/struts2/tutorial/img/logo.gif.
How could I do?Thanks.
 
 
JK.Webster

Phil Zoio

unread,
Mar 31, 2010, 4:04:10 AM3/31/10
to impala...@googlegroups.com
Jokoul

If setServletPath="", then it should work with the image placed in the
package folder struts2/img (corresponding with the package struts2.img
on the classpath)

corresponding to the URL

http://localhost:8080/mydemo-host/struts2/img/logo.gif

with setServletPath = "/struts2"

the same URL would work with the image in the package folder img

The struts2 package should have nothing to do with it.

Phil

jokoul webster

unread,
Mar 31, 2010, 8:42:41 AM3/31/10
to impala...@googlegroups.com
Phil,I really had tried setServletPath = "/struts2",but it didn't work,because there was a struts2 package "tutorial" defined in struts2.xml
=============================================
<package name="tutorial" extends="struts-default">
......
</package>
=============================================
So,if <web:to-module prefix = "/struts2"  setServletPath="true" servletPath="/struts2"/>,then I had the "http error 404, /mydemo-host/struts2/Myimg.jsp" exception.
What can I do?Thanks
 
JK.Webster

Phil Zoio

unread,
Mar 31, 2010, 10:41:32 AM3/31/10
to impala...@googlegroups.com
Jokoul

Yes, I've taken a closer look and there does appear to be a problem -
apparently the JSP support does not like it when you set the
setServletPath="true" flag.

I'll look into this, and try suggest a workaround in the meantime shortly.

Cheers,
Phil

Phil Zoio

unread,
Apr 1, 2010, 5:59:08 AM4/1/10
to impala...@googlegroups.com
Yokoul,

I have now fixed this issue - it should all be working correctly, please let me know if you encounter anything else:

See http://code.google.com/p/impala/issues/detail?id=314

Here's the changeset: http://code.google.com/p/impala/source/diff?spec=svn5441&r=5441&format=side&path=/trunk/impala/impala-web/src/org/impalaframework/web/servlet/wrapper/request/MappedHttpServletRequest.java

I have also updated the Webframeworks sample (now showing the gif in the Struts sample) with the latest snapshot, and uploaded the latess snapshot. (See the Snapshot build link on the home page: http://code.google.com/p/impala/)

Cheers,
Phil

Phil Zoio

unread,
Apr 1, 2010, 6:21:45 AM4/1/10
to impala...@googlegroups.com
Also, a nice side effect of this change is that you no longer need to use the ModuleJspServlet mapped to *.jsp in web.xml

The JSP support it enabled simply using a to-handler mapping and the web:jsp-servlet. The XML for the struts 2 module in the Web Frameworks example is now:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>

        <web:mapping>
                <web:to-module prefix = "/struts2" setServletPath="true"/>
                <web:to-handler extension = "action" filterNames="webframeworks-struts2"/>
                <web:to-handler extension = "gif" servletName="struts2Resources"/>
                <web:to-handler extension = "jsp" servletName="jspServlet"/>

        </web:mapping>

        <web:filter id = "myStruts2Filter"
                delegatorFilterName = "webframeworks-struts2"

                filterClass = "org.apache.struts2.dispatcher.FilterDispatcher"  >
        </web:filter>
       
        <web:servlet id = "struts2Resources"
            servletClass = "org.impalaframework.web.servlet.ResourceServlet"
            initParameters = "cacheTimeout=10"/>

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

Phil

jokoul webster

unread,
Apr 1, 2010, 12:49:20 PM4/1/10
to impala...@googlegroups.com
Hi Phil,if the images folder name is "struts2",it works,but if I rename the folder name,it doesn't work,why?
Thanks
 
JK.Webster

Phil Zoio

unread,
Apr 1, 2010, 2:16:18 PM4/1/10
to impala...@googlegroups.com
What does your struts2 application context look like? I'll need so see
that to offer an explanantion ...

I presume you are using the snapshot update ...

jokoul webster

unread,
Apr 1, 2010, 2:46:18 PM4/1/10
to impala...@googlegroups.com
sorry,not images folder name,but  jsps folder name.
 
A:it works 
==============struts.xml========================
<package name="tutorial" extends="struts-default">
        <action name="MyBatch" class="org.impalaframework.webframeworks.struts2.MyBatchDemo">
            <result>/struts2/MyBatch.jsp</result>
        </action>
......
</package>
==============mydemo-struts2-context.xml=========================
<web:mapping>
  <web:to-module prefix = "/struts2"  setServletPath="true" />
  <web:to-handler extension="jsp" servletName="mydemo-jsp"/>
  <web:to-handler extension="action" filterNames="mydemo-struts2"/>
  <web:to-handler extension = "gif" servletName="mydemo-resources"/>
 </web:mapping>
 <web:filter id = "myStruts2Filter"
  delegatorFilterName = "mydemo-struts2"

  filterClass = "org.apache.struts2.dispatcher.FilterDispatcher"  >
 </web:filter>
  
  <web:jsp-servlet id="mydemo-jsp"/>

 
 <web:servlet id = "mydemo-resources"
        servletClass = "org.impalaframework.web.servlet.ResourceServlet"
        initParameters = "cacheTimeout=10"/>
=================================================
 
B:it doesn't work if I have renamed the jsp folder name "struts2" to "jsp"
<package name="tutorial" extends="struts-default">
        <action name="MyBatch" class="org.impalaframework.webframeworks.struts2.MyBatchDemo">
            <result>/jsp/MyBatch.jsp</result>
        </action>
......
</package>
 
 

Phil Zoio

unread,
Apr 1, 2010, 5:27:18 PM4/1/10
to impala...@googlegroups.com
It is possible by tweaking the values for servletPath="...", but it will
also mean you will need to change your image location and folder name,
so I wouldn't recommend this - I don't think this make things any simpler.

Phil

> <result>/*jsp*/MyBatch.jsp</result>
> </action>
> ......
> </package>
>
>

jokoul webster

unread,
Apr 1, 2010, 10:35:11 PM4/1/10
to impala...@googlegroups.com
Phil,I guess you recommend us must to keep the jsp folder name as same as the value of current module prefix property?I am not sure sometimes whether we will go in to trouble。
 
 
JK.Webster

Phil Zoio

unread,
Apr 2, 2010, 4:56:48 AM4/2/10
to impala...@googlegroups.com
On further reflection I will enable a change which will remove the restriction that the JSP path needs to start with the module prefix. I think that will make the internal module JSP mapping more intuitive.

See http://code.google.com/p/impala/issues/detail?id=316

Phil

jokoul webster

unread,
Apr 3, 2010, 2:36:45 PM4/3/10
to impala...@googlegroups.com
Phil:
  1:Now,within a Sturts2 individual web module we can display images only keep the jsp folder name as same as module prefix,but unfortunately,in this case ,images can not be displayed within a individual Spring MVC web module.
   2:Which servlet sould be fit for css files,"org.springframework.js.resource.ResourceServlet" or " org.impalaframework.web.servlet.ResourceServlet"?
 
 
JK.Webster

Phil Zoio

unread,
Apr 9, 2010, 4:19:54 PM4/9/10
to impala...@googlegroups.com
Jokoul

See the answers below.

Phil

jokoul webster wrote:
> Phil:
> 1:Now,within a Sturts2 individual web module we can display images only
> keep the jsp folder name as same as module prefix,but unfortunately,in this
> case ,images can not be displayed within a individual Spring MVC web module.
>

Check out the URL mapping sample, which uses the resource servlet to
serve CSS (although not for images, although adding this should be
trivial) within a Spring MVC-based application.

See http://code.google.com/p/impala/wiki/SamplesURLMapping


> 2:Which servlet sould be fit for css
> files,"org.springframework.js.resource.ResourceServlet" or "
> org.impalaframework.web.servlet.ResourceServlet"?
>

You can use either. Actually, the Impala version is taken directly from
the Spring version (saves you having to add the extra Spring JS
dependency, which contains quite a lot of JavaScript specific stuff
which is not very interesting for me)
>
> JK.Webster
>
>

Reply all
Reply to author
Forward
0 new messages