You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas CORNET <th...@cornet.name> on 2003/03/03 00:27:59 UTC

Modules


         Hi all :)

     I hope someone will have a clue for me, because I'm fighting against 
Struts modules for a couple of weeks now, and nothing works.

     According to the few tutorials available on Net about struts' modules, 
all is very easy. Here is what I've understand :

a) create a subdir in your application named for example 'guestbook'
b) declare in your web.xml another init parameter such as :

     <init-param>
         <param-name>config/guestbook</param-name>
         <param-value>/WEB-INF/struts-config-guestbook.xml</param-value>
     </init-param>

c) create the struts-config-guestbook.xml and fill it with forms, actions, ...
d) now, every page in the 'guestbook' directory will access first the 
struts-config-guestbook.xml to search for actions, forms, forwards ....

     If I'm wrong at this point, explain me plz what I missed.


     I did every step of these tutorials and each time, it says (page URL 
is http://localhost/aejase/guestbook/guestbook.jsp) :

          [ServletException in:/guestbook/tiles/guestbook.jsp] Cannot 
retrieve mapping for action /addguestbook'


     What i did next is to create a page 'test.jsp' in my 'guestbook' 
directory. I've searched in the Form tag java source to see how it's 
reaching the action's properties, and I've used the same methods and 
classes to display the current module's properties of test.jsp. Here is the 
JSP code :

------------------------------

// part 1

org.apache.struts.config.ModuleConfig cfg = 
org.apache.struts.util.RequestUtils.getModuleConfig(pageContext);
org.apache.struts.config.ActionConfig[] actions = cfg.findActionConfigs();

out.println("URL : " + 
org.apache.struts.util.RequestUtils.requestURL(request).toString() + "<br>");

out.println("current module's prefix : >" + cfg.getPrefix() + "<<br>");
out.println("current module's number of actions : " + actions.length + "<br>");

for (int i = 0; i < actions.length; i++)
{
out.println("action's name #" + (i+1) + " : " + actions[i].getName() + "<br>");
out.println("action's path #" + (i+1) + " : " + actions[i].getPath() + "<br>");
out.println("action's prefix #" + (i+1) + " : " + actions[i].getPrefix() + 
"<br>");
}

// part 2

String[] mc = 
org.apache.struts.util.RequestUtils.getModulePrefixes(application);

for (int i = 0; i < mc.length; i++)
out.println("<br> application's modules prefix -> " + mc[i]);

// part 3

out.println("<p>getModuleName(request, application) : " + 
org.apache.struts.util.RequestUtils.getModuleName(request, application));


----------------------------------

a) Output of part 1:

=======================

URL : http://localhost/aejase/guestbook/test.jsp
current module's prefix : ><
current module's number of actions : 1
action's name #1 : quicksearchForm
action's path #1 : /quicksearch
action's prefix #1 : null

========================

My conclusion : the module used by my test page is the default one 
(no-prefix). To prove this, I've listed all the actions of the module, and 
the result is the actions of my struts-config.xml file. So I can't call the 
action of my struts-config-guestbook.xml file. Question : why doesn't 
struts use the guestbook module ? Did I do something wrong ??


b) Output of part 2 is :

==========================

application's modules prefix -> /quicksearch
application's modules prefix -> /guestbook

===========================

It lists all the modules prefix available for the application. All is 
working file, the webapp knows all my modules.


c) Output of part 3 is :

===========================

getModuleName(request, application) : /guestbook

===========================

Just a try, using RequestUtils.getModuleName(request, application)... It 
seems to work well, i don't understand why, when i've seen output 1.



I don't seem to reach the solution, and i hope some higher intelligence can 
help me. Thanks in advance for all anwer :)



                                                 Thomas

Configuration :

Windows XP Pro
Tomcat 4.1.18 under Apache Tomcat 2.0.44 with JK2 connector
Struts 1.1-rc1
J2DSK 1.4.1_01


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


Re: Modules

Posted by Eddie Bush <ek...@swbell.net>.
> Many thanks for the explainations. Things like this are not present on 
> tutorials on Net. It must be time for me to buy a big book about 
> Struts ;) 


Actually ... I know for a fact that information is present in the users 
guide.  I put it there :-)  At least, I felt I made it that clear. 
 Maybe I should revise what's there?

> I see the need to place the JSP under WEB-INF directory, but is it 
> possible, according recommandations, to let a minimum of JSP out of 
> the WEB-INF directory for the front pages of a webapp ? 

You never really *have* to expose even a single JSP.  Just stuff them 
off under WEB-INF (say WEB-INF/jsp or some such) and then forward to 
them through your actions.  You can reach anything under WEB-INF by 
forwarding to it.  There was a day when this wasn't as clearly-stated in 
the spec as it is now, and not all containers supported it.  I believe 
those days are past.  Certainly, Tomcat (and many others) support it -- 
it is spec-compliant behavior.

> However, I'm going to follow your recommandations to make those 
> modules work. Don't waste time on it, I'll bother you only if it's 
> still not working :) 

Ok.  I'm going to grab some shut-eye then.  The morning seems to have 
snuck up on me :-( again ...

>                              Thomas 


-- 
Eddie Bush





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


Re: Modules

Posted by Thomas CORNET <th...@cornet.name>.
>
>Most everything knows how to get at the configuration for the default 
>module.  You see, most configuration data is available in two places: 1) 
>application scope under a combination of whatever the key is that 
>identifies that given piece of data -- plus a module identifier.  2) in 
>request scope [if you go through the controller] under the key identifying 
>that piece of data, but without the module identifier.
>
>Some things will go on to app scope and pull things from there.  The data 
>you're working with if you don't go through the controller to get at 
>things (ie.  you don't go through an action to get at your JSP pages) will 
>be the data for the main (default) module.  Only by going through the 
>controller (ie. invoking pages through actions) will the controller have 
>the opportunity to determine which module is being invoked and place the 
>data relevant to that module in the request.  That's why things work as 
>expected if you put your configuration into the default config file.
>
>Still clear as mud?
>
>RULE:  Always go through the controller.  (always use an action to get at 
>a JSP)  This is a really strong recommendation for folks not using 
>modules, but it really becomes an absolute must when you are using 
>modules.  Sorry, but there's no way go get around it without rewriting 
>Struts to be a filter instead of a servlet (... which might possibly 
>happen in Struts 2.x.x - we've speculated on this point)



>You can let yourself get carried away with it like a lot of folks do and 
>hide your JSPs off under WEB-INF, if you like (TONS of folks do this, and 
>I've taken to it as well).  This will make it impossible to access a 
>resource unless you go through an action.  This both ensures that the user 
>can't inadvertantly access the page directly, and ensures you write an 
>action to reach it.  It's really a handy trick on a lot of levels.
>
>Users can bookmark actions just like they can pages.  They're just storing 
>the URL.  Yes, you'll have to have request parameters cluttering your URL, 
>but it can be done.  They can handle it (or, I should say, the browser 
>can) just fine.  I can't count the times I've saved queries on 
>pricegrabber.com -- same principle.
>
>I haven't examined your files yet.  Sorry, but I really don't have time 
>right now :-(  What I would do if I were you is to make everything go 
>through an action and see if you're still having problems.  If you're 
>always going through the controller, everything should always be A-OK. If 
>you do continue to have problems once you've fixed your application to act 
>as I have stated, please do let us know.
>
>Here's another perspective:  If you don't go through the controller, how 
>is the page supposed to know which module you're invoking it from?  I 
>guess you could hard-code it -- and you could actually get at your 
>configuration data (study source code and user guide) if you knew which 
>module you were in.  Unfortunately, without hard-coding it or going 
>through the controller, there's no way a page has a clue which module it's 
>a part of.  That information is something that is perculiar only to your 
>Struts configuartion - and the controller is the only one capable of 
>changing which module you're in.  Is it becoming any clearer why this is a 
>requirement?
>
>If we ever do swap over to having the controller be a filter instead of a 
>servlet, we'll be able to tell very easily if a JSP lives in a certain 
>module and will be able to go directly to pages if we so choose.  Until 
>then, you've simply got to get over whatever reasons you have for not 
>prefacing all pages with an action and ... like Nike would say ... "Just 
>Do It!"
>
>HTH!
>
>Eddie
>
>--
>Eddie Bush

Many thanks for the explainations. Things like this are not present on 
tutorials on Net. It must be time for me to buy a big book about Struts ;)

I see the need to place the JSP under WEB-INF directory, but is it 
possible, according recommandations, to let a minimum of JSP out of the 
WEB-INF directory for the front pages of a webapp ?

However, I'm going to follow your recommandations to make those modules 
work. Don't waste time on it, I'll bother you only if it's still not working :)

                              Thomas





>---------------------------------------------------------------------
>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


Re: Modules

Posted by Eddie Bush <ek...@swbell.net>.
Thomas CORNET wrote:

> At 03:18 03/03/2003, you wrote:
>
>> You're going through a JSP to invoke an action?  Is the action in a 
>> different module?  Be aware that only by going through the controller 
>> do you enable non-default modules.  If you don't explicitly go though 
>> the servlet (and going through a JSP does not go through the servlet) 
>> then Struts hasn't the opportunity to change to your module (read:  
>> none of your modules information [ mappings, forms, etc ] are 
>> available) and you'll only be able to acheive success if what you 
>> wished to reach was located in the default module.
>>
>> Clear as mud? 
>
> hmmm yes. but when i go to a JSP directly within the site, without 
> passing by the controller, this means that I can't render html:form 
> elements because it doesn't know about the modules ?
>
>> The basics of what you're doing appear correct to me.  I'm not sure I 
>> understand where the breakdown is or why - I would assume it's 
>> developer (the developer being you - not us) error.  I know a lot of 
>> folks have had problems getting their heads around modules - don't 
>> know what could be done to help that.  Do you have any questions 
>> whos' ansers might help you?  Perhaps if you posted or attached your 
>> config?  I've been out of the loop for a bit, so it could just be 
>> brain-rot, but I don't see a definite cause for your problem.  Seeing 
>> your config(s) and knowing precisely how you're invoking things would 
>> help us assist you better. 
>
> I know that's my fault. 99% percent of people achieved to use modules, 
> so I know something is missing...
>
> Here is in attachment, the jsp source, the action and form classes, 
> and the struts config of the module. Just wanted to say all is working 
> well when module's config content is place in the default module's 
> config. 

Most everything knows how to get at the configuration for the default 
module.  You see, most configuration data is available in two places: 
 1) application scope under a combination of whatever the key is that 
identifies that given piece of data -- plus a module identifier.  2) in 
request scope [if you go through the controller] under the key 
identifying that piece of data, but without the module identifier.

Some things will go on to app scope and pull things from there.  The 
data you're working with if you don't go through the controller to get 
at things (ie.  you don't go through an action to get at your JSP pages) 
will be the data for the main (default) module.  Only by going through 
the controller (ie. invoking pages through actions) will the controller 
have the opportunity to determine which module is being invoked and 
place the data relevant to that module in the request.  That's why 
things work as expected if you put your configuration into the default 
config file.

Still clear as mud?

RULE:  Always go through the controller.  (always use an action to get 
at a JSP)  This is a really strong recommendation for folks not using 
modules, but it really becomes an absolute must when you are using 
modules.  Sorry, but there's no way go get around it without rewriting 
Struts to be a filter instead of a servlet (... which might possibly 
happen in Struts 2.x.x - we've speculated on this point)

You can let yourself get carried away with it like a lot of folks do and 
hide your JSPs off under WEB-INF, if you like (TONS of folks do this, 
and I've taken to it as well).  This will make it impossible to access a 
resource unless you go through an action.  This both ensures that the 
user can't inadvertantly access the page directly, and ensures you write 
an action to reach it.  It's really a handy trick on a lot of levels.

Users can bookmark actions just like they can pages.  They're just 
storing the URL.  Yes, you'll have to have request parameters cluttering 
your URL, but it can be done.  They can handle it (or, I should say, the 
browser can) just fine.  I can't count the times I've saved queries on 
pricegrabber.com -- same principle.

I haven't examined your files yet.  Sorry, but I really don't have time 
right now :-(  What I would do if I were you is to make everything go 
through an action and see if you're still having problems.  If you're 
always going through the controller, everything should always be A-OK. 
 If you do continue to have problems once you've fixed your application 
to act as I have stated, please do let us know.

Here's another perspective:  If you don't go through the controller, how 
is the page supposed to know which module you're invoking it from?  I 
guess you could hard-code it -- and you could actually get at your 
configuration data (study source code and user guide) if you knew which 
module you were in.  Unfortunately, without hard-coding it or going 
through the controller, there's no way a page has a clue which module 
it's a part of.  That information is something that is perculiar only to 
your Struts configuartion - and the controller is the only one capable 
of changing which module you're in.  Is it becoming any clearer why this 
is a requirement?

If we ever do swap over to having the controller be a filter instead of 
a servlet, we'll be able to tell very easily if a JSP lives in a certain 
module and will be able to go directly to pages if we so choose.  Until 
then, you've simply got to get over whatever reasons you have for not 
prefacing all pages with an action and ... like Nike would say ... "Just 
Do It!"

HTH!

Eddie

-- 
Eddie Bush





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


Re: Modules

Posted by Thomas CORNET <th...@cornet.name>.
At 03:18 03/03/2003, you wrote:
>You're going through a JSP to invoke an action?  Is the action in a 
>different module?  Be aware that only by going through the controller do 
>you enable non-default modules.  If you don't explicitly go though the 
>servlet (and going through a JSP does not go through the servlet) then 
>Struts hasn't the opportunity to change to your module (read:  none of 
>your modules information [ mappings, forms, etc ] are available) and 
>you'll only be able to acheive success if what you wished to reach was 
>located in the default module.
>
>Clear as mud?

hmmm yes. but when i go to a JSP directly within the site, without passing 
by the controller, this means that I can't render html:form elements 
because it doesn't know about the modules ?

>The basics of what you're doing appear correct to me.  I'm not sure I 
>understand where the breakdown is or why - I would assume it's developer 
>(the developer being you - not us) error.  I know a lot of folks have had 
>problems getting their heads around modules - don't know what could be 
>done to help that.  Do you have any questions whos' ansers might help 
>you?  Perhaps if you posted or attached your config?  I've been out of the 
>loop for a bit, so it could just be brain-rot, but I don't see a definite 
>cause for your problem.  Seeing your config(s) and knowing precisely how 
>you're invoking things would help us assist you better.

I know that's my fault. 99% percent of people achieved to use modules, so I 
know something is missing...

Here is in attachment, the jsp source, the action and form classes, and the 
struts config of the module. Just wanted to say all is working well when 
module's config content is place in the default module's config.

>GL!
>
>Thomas CORNET wrote:

Re: Modules

Posted by Eddie Bush <ek...@swbell.net>.
You're going through a JSP to invoke an action?  Is the action in a 
different module?  Be aware that only by going through the controller do 
you enable non-default modules.  If you don't explicitly go though the 
servlet (and going through a JSP does not go through the servlet) then 
Struts hasn't the opportunity to change to your module (read:  none of 
your modules information [ mappings, forms, etc ] are available) and 
you'll only be able to acheive success if what you wished to reach was 
located in the default module.

Clear as mud?

The basics of what you're doing appear correct to me.  I'm not sure I 
understand where the breakdown is or why - I would assume it's developer 
(the developer being you - not us) error.  I know a lot of folks have 
had problems getting their heads around modules - don't know what could 
be done to help that.  Do you have any questions whos' ansers might help 
you?  Perhaps if you posted or attached your config?  I've been out of 
the loop for a bit, so it could just be brain-rot, but I don't see a 
definite cause for your problem.  Seeing your config(s) and knowing 
precisely how you're invoking things would help us assist you better.

GL!

Thomas CORNET wrote:

>
>
>         Hi all :)
>
>     I hope someone will have a clue for me, because I'm fighting 
> against Struts modules for a couple of weeks now, and nothing works. 


-- 
Eddie Bush





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