aspose file tools*
The moose likes Struts and the fly likes using modules with JSPs behind web-inf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using modules with JSPs behind web-inf" Watch "using modules with JSPs behind web-inf" New topic
Author

using modules with JSPs behind web-inf

Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
I'm using struts 1.2.9 which the struts site claims is the "prime time"
ready version.

I would like to use modules and put my JSPs behind WEB-INF to protect them. When I try this with struts, it rewrites my URL with the module name and causes 404 errors on validation failures.

I read all over the net that I need to change my forwardPattern & pagePattern in my controller to "/WEB-INF/$M$P", but again, the struts site docs explicitly state that anything other then $$, $M and $P are "silently swallowed". (http://struts.apache.org/struts-doc-1.2.9/userGuide/configuration.html)

currently, my input param is:
input="/WEB-INF/struts/modules/FOOModule/jsp/foo.jsp"

I want coworkers to be able to have input params like:
input="/WEB-INF/struts/modules/BARModule/jsp/bar.jsp"

developing in WSAD 5.1.2
will deploy to WAS 5

The default struts config is empty, and I want to keep it that way. Our existing WAR has numerous non-struts servlets. I have added the needed lines to web.xml to use the struts controller. The idea is future development would be in struts, but we don't want to mess with existing code right now. We would like to see all new development occurr in "WEB-INF/struts/modules/YOU_MODULE_NAME" with two subdirectories: "CONFIG" and "JSP". Your module's struts config goes into CONFIG and your module's JSPs go into JSP. That way, every developer can work independantly of any other developer.

Been trying to get this to work for almost two weeks now. I'm beginning to wonder if it's even possible.

Any help appreciated.

Jason
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Jason,

Give us an example of:

* One of your Action mappings (the <action> tag in struts-config.xml)
* The URL that Struts is actually returning when validation fails on that action.
[ May 15, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
Merrill and Company.

using struts 1.2.9
(cause struts.apache.org says it's the production ready version)

I have the following files:
/WebContent/MyApp/index.jsp
/WEB-INF/struts/modules/MyApp/config/struts-config.xml
/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp
/WEB-INF/struts/modules/MyApp/jsp/VerifyCustomer.jsp
/WEB-INF/struts/modules/MyApp/jsp/VerifyEmployee.jsp
/WEB-INF/struts-config.xml (has NO entries)
/WEB-INF/web.xml

web.xml has:
<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>
<init-param>
<param-name>config/MyApp</param-name>
<param-value>WEB-INF/struts/modules/MyApp/ (split for readability)
config/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
//normal tablibs bean/html/logic/nested/tiles
</taglib>


index.jsp contains:
<logic:redirect action="/MyApp/CollectInfo.do"/>


struts config contains:
<action path="/CollectInfo"parameter="/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp"
type="org.apache.struts.actions.ForwardAction"/>


IdentifyCustomer.jsp has a form tag:
<html:form action="/ProcessIdentity" method="post">


Then again in my struts config I have:
<action path="/ProcessIdentity"
type="MyApp.actions.ProcessIdentity"
name="IdentifyCustomerForm"
validate="true"
input="/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp" >
<forward
name="verifyEmployee"
path="/WEB-INF/struts/modules/MyApp/jsp/VerifyEmployee.jsp"/>
<forward
name="verifyStaff"
path="/WEB-INF/struts/modules/MyApp/jsp/VerifyCustomer.jsp" />
</action>


My Problem:

when I submit an incomplete IdentifyCustomer.jsp page the validator sees the failure it tries to send me back to:

' input="/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp" '

so I can complete the form. Problem is instead of seeing the form with previously entered data, I get a 404 error in my browser:

Error 404: /MyApp/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp

Notice the interjection of "MyApp" before WEB-INF. This is wrong.

How does struts send users back to the input page...is it a forward?

How can I fix this problem,

Jason Berk
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Try this:

In your struts-config.xml file, specify:

<controller inputForward="true" />

This tells the controller that whenever you specify an input, you'll be specifying a forward, rather than an actual URI.

Then in your ProcessIdentity Action, create a new forward:

<forward
name="backToCustomer"
path="/WEB-INF/struts/modules/MyApp/jsp/IdentifyCustomer.jsp"/>

and in your <action> tag:

<action path="/ProcessIdentity"
type="MyApp.actions.ProcessIdentity"
name="IdentifyCustomerForm"
validate="true"
input="backToCustomer" >
Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
Thanks Merrill. I actually stumbled onto that solution myself after my post. Is it me or is the documentation for struts "a mess". I would still like to know where all these websites came up with the idea of setting the forward/page Pattern to "/WEB-INF/$M$P". I find NOTHING on the struts site that leads me to believe that's ever been possible. It's difficult enough to wrap your head around struts alone....the last thing we need is false documentation.

Jason
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
the struts site docs explicitly state that anything other then $$, $M and $P are "silently swallowed"

I have not used this feature, but I am interpreting the documentation differently that you are. Here is the statement:

$x - (Where "x" is any character not defined above) Silently swallowed, reserved for future use.

This seems to be saying that $M, $P and $$ all have special meanings but that if I enter $A or $X that will be ignored. I do not read this to mean that I cannot put a constant string such as "WEB-INF" on the front. Oh well...it sounds like you got it working for you.

- Brent
Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
using a DTD validator, if I set either field to something other then $M $P $$ or $X I get the following warning:

Pattern should consist [of] any combination of the following: "$M" "$P" "$$" "$x"

and since $x doesn't do anything and I can't imagine who would use $$, that only leaves $m and $p

Jason
 
Don't get me started about those stupid light bulbs.
 
subject: using modules with JSPs behind web-inf