struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@lexmark.com
Subject [Off Topic] re-pre-compiling only jsps that have changed - was Re: Filter to redirect to welcome action when pre-compiling JSPs
Date Tue, 25 Mar 2003 17:44:53 GMT

Hi.  Apologies for going slightly off topic (!), and the long title, but
with all this talk about pre-compiling JSPs, thought I'd jump in with a
question that relates to jasper no-longer recognising when a file has
changed due to the new "_jsp" which it seems to add to the end of files it
compiles.

This proves VERY frustrating when using Ant in development, as you have to
pre-compile *all* your jsp's everytime you make a change, and then restart
the server.

Surely there is a way round this.  Has anyone else see it?

Many thanks,

David





Jason Lea <jason@kumachan.net.nz> on 03/25/2003 02:23:03 AM

Please respond to "Struts Users Mailing List"
       <struts-user@jakarta.apache.org>

To:    Struts Users Mailing List <struts-user@jakarta.apache.org>
cc:
Subject:    Re: Filter to redirect to welcome action when pre-compiling
       JSPs


gaffer wrote:
> Hi Jason,
>
> At this very moment, I am trying to solve a similar issue. Would you
> mind posting the relevant snippets from web.xml and struts-config? Such
> as paths to actions, url-pattern, etc.
>
> Thanks
> Al

Ok, here goes...

web.xml:
<web-app>
   ...
   <!-- Filter: redirect to Struts forwardName-->
   <filter>
     <filter-name>WelcomeFilter</filter-name>
     <filter-class>nz.net.kumachan.project.WelcomeFilter</filter-class>
     <init-param>
       <param-name>forwardName</param-name>
       <param-value>homepage</param-value>
     </init-param>
   </filter>
   ...
   <filter-mapping>
     <filter-name>WelcomeFilter</filter-name>
       <url-pattern>/</url-pattern>
   </filter-mapping>
   ...
   <!-- Standard Action Servlet -->
   <servlet>
     <servlet-name>action</servlet-name>
     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
     <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/struts-config.xml</param-value>
     </init-param>
     <load-on-startup>3</load-on-startup>
   </servlet>

   <!-- Standard Action Servlet Mapping -->
   <servlet-mapping>
     <servlet-name>action</servlet-name>
     <url-pattern>*.do</url-pattern>
   </servlet-mapping>
   ...
</web-app>

Note:
I don't have a <welcome-file-list> defined in web.xml.
My WelcomeFilter takes a Struts Global Forward, looks up the forward (in
this case it would return "/Homepage.do").  I could have just put
"/Homepage.do" as the forwardName and use
req.getRequestDispatcher(forwardName).forward(req,res) instead of
messing with the Struts code.  Hmm, maybe that would be nicer... I might
change it now :)



struts-config.xml:
<struts-config>
   ...
   <global-forwards>
     ...
     <forward
       name="homepage"
       path="/Homepage.do"/>
     ...
   <global-forwards>
   ...
   <action-mappings>
     ...
     <action
       path="/Homepage"
       type="org.apache.struts.actions.ForwardAction"
       parameter="main.homepage"/>
     ...
   </action-mappings>
   ...
</struts-config>

Note:
The action "/Homepage" forwards to the parameter "main.homepage" which
maps to a Tiles definition eg in tiles-defs.xml:

   <definition name="main.homepage" extends=".mainLayout">

but I could have used something like "WEB-INF/jsp/pages/Homepage.jsp"
for the parameter


Hope this helps...

Jason Lea

>
>
> On Mon, 2003-03-24 at 22:01, Jason Lea wrote:
>
>>Cool.  It's good to know someone else has done this.  I thought I should
>>post this just so someone else looking at pre-compilation of JSPs would
>>find it useful, but also to see if there are any glaring issues or if it
>>is a Good Thing (TM)  :-)
>>
>>Jason
>>
>>David Graham wrote:
>>
>>>This is exactly what I did :-).
>>>
>>>David
>>>
>>>
>>>
>>>
>>>>From: Jason Lea <jason@kumachan.net.nz>
>>>>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>>>>To: Struts Users Mailing List <struts-user@jakarta.apache.org>
>>>>Subject: Filter to redirect to welcome action when pre-compiling JSPs
>>>>Date: Tue, 25 Mar 2003 17:47:14 +1200
>>>>
>>>>I have been playing around with JSP pre-compilation with Tomcat-4.1.24
>>>>(http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jasper-howto.html) so
>>>>I can check my JSP pages for compiler errors before deployment, but
>>>>also to remove the delay that the first hit incurs.
>>>>
>>>>The only problem with this is the <welcome-file> which has to point
to
>>>>a physical jsp page and not a servlet.  The Struts in Action book
>>>>suggests  using a index.jsp page with a <logic:redirect> to a Welcome
>>>>action, which is what I was doing.
>>>>
>>>>I tried creating a servlet that would forward the request onto my
>>>>Welcome action & servlet-mapping with a <url-pattern>/<url-pattern>,
>>>>but this seemed to match any request and cause lots of problems.
>>>>
>>>>So I dropped that idea and instead have used a filter...
>>>>
>>>><filter-mapping>
>>>>  <filter-name>WelcomeFilter</filter-name>
>>>>  <url-pattern>/</url-pattern>
>>>></filter-mapping>
>>>>
>>>>which works perfectly.  It only fires for http://localhost/app/ or
>>>>http://localhost/app and my filter forwards the request onto my
>>>>Welcome action correctly.
>>>>
>>>>I can now get rid of index.jsp and all my other JSPs are pre-compiled.
>>>>I have also hidden all of my JSPs under the WEB-INF so they cannot be
>>>>called directly and have to go through my Struts actions.
>>>>
>>>>
>>>>Jason Lea
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>>_________________________________________________________________
>>>Protect your PC - get McAfee.com VirusScan Online
>>>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>


--
Jason Lea
Email:     jason@kumachan.net.nz
Phone/Fax: +64  3 381 2907
Mobile:    +64 21 040 2708
Address:   9a Tabart Street, Christchurch, New Zealand


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org









---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message