You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken Pelletier <ke...@nika.com> on 2003/03/13 04:55:19 UTC

Struts 1.1 modules and logic:forward

I have an application with 3 motules, each having it's own struts 
config file (naturally).

Each module has it's own welcome file ( index.jsp ) which forwards to 
an action.

Eg:

/myapp/module1/index.jsp:
....
<logic:forward name="login"/>
...

The forward tag does not find the global action forward named "login" 
in the *module's* config file.  However, if I place a global action 
forward by that name in the *default* config file, it finds it there.

Should the forward tag be aware that it's within a module subdirectory, 
and use the module's config, or is this not possible since it's not 
going through the struts action servlet, being a jsp?

What's an alternative that will be module-aware?








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


Re: Struts 1.1 modules and logic:forward

Posted by Ken Pelletier <ke...@nika.com>.
Ed,

Thanks for the quick response.  :-)

It wasn't obvious at the start that the tag wouldn't use the same 
mapping inference machinery that the controller uses to map physical 
request paths to the module config.

I can see your point about not always having your pages physically 
organized around your logical structure, but in this particular case 
the index.jsp's raison d'etre is precisely to provide entry points that 
mirror the logical structure, and so it's physically located 
accordingly.

>  How can you expect for the controller to know which module you're in 
> - based off the contents of some file out there - when you haven't 
> gone through it via a URL yet?

The controller itself uses RequestUtils to map the request to their 
module config.  It seems the tag could have as well, and I suppose I 
expected it would when I first tried it.

Preceding the <logic:forward> tag with the following one liner in 
index.jsp indeed does do the proper mapping and gets the module config 
into request scope, causing the forward tag to then get the named 
ActionForward from the module.

<% RequestUtils.selectModule( request, getServletConfig() ); %>

I'm not suggesting that this sort of jiggery-pokery is appropriate, but 
just that it isn't exactly far fetched.  :-)

I do sincerely thank you for your very thorough response, it did 
clarify things for me!

- Ken


On Thursday, March 13, 2003, at 09:58  AM, Eddie Bush wrote:

> Well, what I said is somewhat applicable.  How can you expect for the 
> controller to know which module you're in - based off the contents of 
> some file out there - when you haven't gone through it via a URL yet?  
> I do actually see *your* point now, as well, since I've gotten some 
> sleep!
>
> Ok.  Lets sit down and ask some questions:
>
>    - Must our physical (on-disk) structure match our logical 
> (URL-based) structure?
>        - No, we map our logical addresses to their physical location.
>
> Many folks stuff their JSP pages off under WEB-INF/pages (or some 
> similar location) and further organize them based on the module they 
> are contained in (or some other secondary sort).  This means that, 
> while host.mydomain.com/myContext/ will point to an index file (which 
> will boot-strap the user into the application), there may not be other 
> index files for other (logical) "directories" in your application.  
> You could create physical paths to mirror your logical structure, or 
> you could just expect the user to use the "front door" :-)
>
>    - Should our users have multiple entry points to our application?
>        - Perhaps, it's up to you.
>
> One thing you have to bear in mind however - as I've reiterated time 
> and again - is that the Struts controller works with our logical, 
> URL-based structure to determine which module the user would like to 
> operate in. All of the Struts machinery depends upon the controller 
> having made this analysis and the configuration that goes along with 
> it (placing configuration data relevant to the module into the 
> request).  You're expecting a taglib to be as intelligent as the 
> controller - based off a request for a *physical* (we said the 
> controller worked with *logical* paths) path.  How would you suggest 
> it do this?
>
> Probably the way to go about this, if it's a strict requirement, is to 
> actually create a physical structure that mirrors your logical 
> structure (as it sound you have already done) and then create your 
> index files and use a logic:redirect.  Use the href attribute instead 
> of the name or forward attributes.  This way, you can (little as any 
> of us may like it) hard-code the module path.  You'll basically send 
> the user from /module-path/index.jsp to /module-path/index.do.  Do do 
> a redirect instead of a forward.  This way, the URL will change.  This 
> will help you "train" your user-based to use a *.do pattern instead of 
> a *.jsp pattern.
>
> One of these days :-) when the Struts controller becomes a filter 
> we'll be able to do a lot of fancier things - like telling which 
> module a user is working out of based off the direct invocation of a 
> JSP.  In the mean-time, the controller is a servlet - we have to 
> somehow clue it in on where we want it operating from.  Doing a 
> redirect to your logical index will accomplish that.
>
> Better?  ;-)
>
> I know there are a ton of examples out there showing the technique 
> you're using (actually, I think they cause a redirect instead of a 
> forward), but modules really change game-play.  You've got to really 
> be thinking about what you're asking the Struts machinery to infer.  
> Some things it can - some it cannot.  The only module you'll be able 
> to reference without going through the controller first is the default 
> application.  This is why you observed the behavior you did.
>
> I'm sorry I didn't give you the long-winded version to start out with. 
> I tend to expect folks to read between the lines more than they do (ie 
> read "you've got to go through the controller" and understand "you're 
> not accessing the module you want to be accessing").  My appologies 
> for the confusion and delay in answering your question.  Hopefully I 
> answered you better this time around.  If not, just yell back at us.  
> My schedule is very irradic lately, but I'll be in later - there are 
> many other folks well versed on this that could pipe up in my absence 
> too :-)
>
> Regards,
>
> Eddie
>
> Ken Pelletier wrote:
>
>> It seems maybe my question wasn't quite clear.
>>
>> I'm using a welcome-file ( index.jsp ) in each module's directory *to 
>> do exactly that*: force all access through an action.  Unfortunately, 
>> it's not practical to expect everybody to know an action URL in 
>> advance in order to get into your site; this technique seems like a 
>> quite common way of forcing default URL's into an initial action.  
>> The index.jsp's do nothing more than forward to an action.
>>
>> Since there's no action ( and hence no action controller ) involved 
>> in the initial bootstrap welcome file, I was really asking whether 
>> the logic:forward tag could/should be able to infer the appropriate 
>> module config from it's path.  I presume not, given its behavior.
>>
>> - Ken
>>
>> On Thursday, March 13, 2003, at 02:55  AM, Eddie Bush wrote:
>>
>>> Anytime modules are involved, it is imperative that you invoke your 
>>> pages by going through actions (thus, going through the controller). 
>>>  It is only by doing this that you trigger a change from one module 
>>> to another.  The controller is "rigged" to automatically expect you 
>>> to be going to the default module.  By giving it a URL that "leads" 
>>> into a different module, you cause the configuration for that module 
>>> to be placed into the request.  Most things, failing finding this 
>>> information in the request, will look in a similar spot in 
>>> application scope - the "similar spot" points to configuration data 
>>> for the default module.
>>>
>>> It has always been good practice to preface all of your pages with 
>>> an action.  If you're using modules, this is an absolute necessity.
>>> It has always been good practice to preface all of your pages with 
>>> an action.  If you're using modules, this is an absolute necessity.
>>> It has always been good practice to preface all of your pages with 
>>> an action.  If you're using modules, this is an absolute necessity.
>>> It has always been good practice to preface all of your pages with 
>>> an action.  If you're using modules, this is an absolute necessity.
>>>
>>> No, I didn't stutter; nor am I trying to be rude.  I'm just hoping 
>>> that will catch the eye of folks glancing over the email.  This is 
>>> the one problem everyone that has problems with modules seems to 
>>> have.  If you don't go through the controller, you don't have a 
>>> chance of switching modules.
>>>
>>> Ken Pelletier wrote:
>>>
>>>> I have an application with 3 motules, each having it's own struts 
>>>> config file (naturally).
>>>>
>>>> Each module has it's own welcome file ( index.jsp ) which forwards 
>>>> to an action.
>>>>
>>>> Eg:
>>>>
>>>> /myapp/module1/index.jsp:
>>>> ....
>>>> <logic:forward name="login"/>
>>>> ...
>>>>
>>>> The forward tag does not find the global action forward named 
>>>> "login" in the *module's* config file.  However, if I place a 
>>>> global action forward by that name in the *default* config file, it 
>>>> finds it there.
>>>>
>>>> Should the forward tag be aware that it's within a module 
>>>> subdirectory, and use the module's config, or is this not possible 
>>>> since it's not going through the struts action servlet, being a >>>> jsp?
>>>>
>>>> What's an alternative that will be module-aware?
>>>
>>> -- 
>>> Eddie Bush
>>
>
> -- 
> Eddie Bush
>
>
>
>
>
> ---------------------------------------------------------------------
> 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: Struts 1.1 modules and logic:forward

Posted by Eddie Bush <ek...@swbell.net>.
Well, what I said is somewhat applicable.  How can you expect for the 
controller to know which module you're in - based off the contents of 
some file out there - when you haven't gone through it via a URL yet?  I 
do actually see *your* point now, as well, since I've gotten some sleep!

Ok.  Lets sit down and ask some questions:

    - Must our physical (on-disk) structure match our logical 
(URL-based) structure?
        - No, we map our logical addresses to their physical location.

Many folks stuff their JSP pages off under WEB-INF/pages (or some 
similar location) and further organize them based on the module they are 
contained in (or some other secondary sort).  This means that, while 
host.mydomain.com/myContext/ will point to an index file (which will 
boot-strap the user into the application), there may not be other index 
files for other (logical) "directories" in your application.  You could 
create physical paths to mirror your logical structure, or you could 
just expect the user to use the "front door" :-)

    - Should our users have multiple entry points to our application?
        - Perhaps, it's up to you.

One thing you have to bear in mind however - as I've reiterated time and 
again - is that the Struts controller works with our logical, URL-based 
structure to determine which module the user would like to operate in. 
 All of the Struts machinery depends upon the controller having made 
this analysis and the configuration that goes along with it (placing 
configuration data relevant to the module into the request).  You're 
expecting a taglib to be as intelligent as the controller - based off a 
request for a *physical* (we said the controller worked with *logical* 
paths) path.  How would you suggest it do this?

Probably the way to go about this, if it's a strict requirement, is to 
actually create a physical structure that mirrors your logical structure 
(as it sound you have already done) and then create your index files and 
use a logic:redirect.  Use the href attribute instead of the name or 
forward attributes.  This way, you can (little as any of us may like it) 
hard-code the module path.  You'll basically send the user from 
/module-path/index.jsp to /module-path/index.do.  Do do a redirect 
instead of a forward.  This way, the URL will change.  This will help 
you "train" your user-based to use a *.do pattern instead of a *.jsp 
pattern.

One of these days :-) when the Struts controller becomes a filter we'll 
be able to do a lot of fancier things - like telling which module a user 
is working out of based off the direct invocation of a JSP.  In the 
mean-time, the controller is a servlet - we have to somehow clue it in 
on where we want it operating from.  Doing a redirect to your logical 
index will accomplish that.

Better?  ;-)

I know there are a ton of examples out there showing the technique 
you're using (actually, I think they cause a redirect instead of a 
forward), but modules really change game-play.  You've got to really be 
thinking about what you're asking the Struts machinery to infer.  Some 
things it can - some it cannot.  The only module you'll be able to 
reference without going through the controller first is the default 
application.  This is why you observed the behavior you did.

I'm sorry I didn't give you the long-winded version to start out with. 
 I tend to expect folks to read between the lines more than they do (ie 
read "you've got to go through the controller" and understand "you're 
not accessing the module you want to be accessing").  My appologies for 
the confusion and delay in answering your question.  Hopefully I 
answered you better this time around.  If not, just yell back at us.  My 
schedule is very irradic lately, but I'll be in later - there are many 
other folks well versed on this that could pipe up in my absence too :-)

Regards,

Eddie

Ken Pelletier wrote:

> It seems maybe my question wasn't quite clear.
>
> I'm using a welcome-file ( index.jsp ) in each module's directory *to 
> do exactly that*: force all access through an action.  Unfortunately, 
> it's not practical to expect everybody to know an action URL in 
> advance in order to get into your site; this technique seems like a 
> quite common way of forcing default URL's into an initial action.  The 
> index.jsp's do nothing more than forward to an action.
>
> Since there's no action ( and hence no action controller ) involved in 
> the initial bootstrap welcome file, I was really asking whether the 
> logic:forward tag could/should be able to infer the appropriate module 
> config from it's path.  I presume not, given its behavior.
>
> - Ken
>
> On Thursday, March 13, 2003, at 02:55  AM, Eddie Bush wrote:
>
>> Anytime modules are involved, it is imperative that you invoke your 
>> pages by going through actions (thus, going through the controller).  
>> It is only by doing this that you trigger a change from one module to 
>> another.  The controller is "rigged" to automatically expect you to 
>> be going to the default module.  By giving it a URL that "leads" into 
>> a different module, you cause the configuration for that module to be 
>> placed into the request.  Most things, failing finding this 
>> information in the request, will look in a similar spot in 
>> application scope - the "similar spot" points to configuration data 
>> for the default module.
>>
>> It has always been good practice to preface all of your pages with an 
>> action.  If you're using modules, this is an absolute necessity.
>> It has always been good practice to preface all of your pages with an 
>> action.  If you're using modules, this is an absolute necessity.
>> It has always been good practice to preface all of your pages with an 
>> action.  If you're using modules, this is an absolute necessity.
>> It has always been good practice to preface all of your pages with an 
>> action.  If you're using modules, this is an absolute necessity.
>>
>> No, I didn't stutter; nor am I trying to be rude.  I'm just hoping 
>> that will catch the eye of folks glancing over the email.  This is 
>> the one problem everyone that has problems with modules seems to 
>> have.  If you don't go through the controller, you don't have a 
>> chance of switching modules.
>>
>> Ken Pelletier wrote:
>>
>>> I have an application with 3 motules, each having it's own struts 
>>> config file (naturally).
>>>
>>> Each module has it's own welcome file ( index.jsp ) which forwards 
>>> to an action.
>>>
>>> Eg:
>>>
>>> /myapp/module1/index.jsp:
>>> ....
>>> <logic:forward name="login"/>
>>> ...
>>>
>>> The forward tag does not find the global action forward named 
>>> "login" in the *module's* config file.  However, if I place a global 
>>> action forward by that name in the *default* config file, it finds 
>>> it there.
>>>
>>> Should the forward tag be aware that it's within a module 
>>> subdirectory, and use the module's config, or is this not possible 
>>> since it's not going through the struts action servlet, being a jsp?
>>>
>>> What's an alternative that will be module-aware?
>>
>> -- 
>> Eddie Bush 
>

-- 
Eddie Bush





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


Re: Struts 1.1 modules and logic:forward

Posted by Ken Pelletier <ke...@nika.com>.
It seems maybe my question wasn't quite clear.

I'm using a welcome-file ( index.jsp ) in each module's directory *to 
do exactly that*: force all access through an action.  Unfortunately, 
it's not practical to expect everybody to know an action URL in advance 
in order to get into your site; this technique seems like a quite 
common way of forcing default URL's into an initial action.  The 
index.jsp's do nothing more than forward to an action.

Since there's no action ( and hence no action controller ) involved in 
the initial bootstrap welcome file, I was really asking whether the 
logic:forward tag could/should be able to infer the appropriate module 
config from it's path.  I presume not, given its behavior.

- Ken

On Thursday, March 13, 2003, at 02:55  AM, Eddie Bush wrote:

> Anytime modules are involved, it is imperative that you invoke your 
> pages by going through actions (thus, going through the controller).  
> It is only by doing this that you trigger a change from one module to 
> another.  The controller is "rigged" to automatically expect you to be 
> going to the default module.  By giving it a URL that "leads" into a 
> different module, you cause the configuration for that module to be 
> placed into the request.  Most things, failing finding this 
> information in the request, will look in a similar spot in application 
> scope - the "similar spot" points to configuration data for the 
> default module.
>
> It has always been good practice to preface all of your pages with an 
> action.  If you're using modules, this is an absolute necessity.
> It has always been good practice to preface all of your pages with an 
> action.  If you're using modules, this is an absolute necessity.
> It has always been good practice to preface all of your pages with an 
> action.  If you're using modules, this is an absolute necessity.
> It has always been good practice to preface all of your pages with an 
> action.  If you're using modules, this is an absolute necessity.
>
> No, I didn't stutter; nor am I trying to be rude.  I'm just hoping 
> that will catch the eye of folks glancing over the email.  This is the 
> one problem everyone that has problems with modules seems to have.  If 
> you don't go through the controller, you don't have a chance of 
> switching modules.
>
> Ken Pelletier wrote:
>
>> I have an application with 3 motules, each having it's own struts 
>> config file (naturally).
>>
>> Each module has it's own welcome file ( index.jsp ) which forwards to 
>> an action.
>>
>> Eg:
>>
>> /myapp/module1/index.jsp:
>> ....
>> <logic:forward name="login"/>
>> ...
>>
>> The forward tag does not find the global action forward named "login" 
>> in the *module's* config file.  However, if I place a global action 
>> forward by that name in the *default* config file, it finds it there.
>>
>> Should the forward tag be aware that it's within a module 
>> subdirectory, and use the module's config, or is this not possible 
>> since it's not going through the struts action servlet, being a jsp?
>>
>> What's an alternative that will be module-aware?
>
>
> -- 
> Eddie Bush
>
>
>
>
>
> ---------------------------------------------------------------------
> 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: Struts 1.1 modules and logic:forward

Posted by Eddie Bush <ek...@swbell.net>.
Anytime modules are involved, it is imperative that you invoke your 
pages by going through actions (thus, going through the controller).  It 
is only by doing this that you trigger a change from one module to 
another.  The controller is "rigged" to automatically expect you to be 
going to the default module.  By giving it a URL that "leads" into a 
different module, you cause the configuration for that module to be 
placed into the request.  Most things, failing finding this information 
in the request, will look in a similar spot in application scope - the 
"similar spot" points to configuration data for the default module.

It has always been good practice to preface all of your pages with an 
action.  If you're using modules, this is an absolute necessity.
It has always been good practice to preface all of your pages with an 
action.  If you're using modules, this is an absolute necessity.
It has always been good practice to preface all of your pages with an 
action.  If you're using modules, this is an absolute necessity.
It has always been good practice to preface all of your pages with an 
action.  If you're using modules, this is an absolute necessity.

No, I didn't stutter; nor am I trying to be rude.  I'm just hoping that 
will catch the eye of folks glancing over the email.  This is the one 
problem everyone that has problems with modules seems to have.  If you 
don't go through the controller, you don't have a chance of switching 
modules.

Ken Pelletier wrote:

> I have an application with 3 motules, each having it's own struts 
> config file (naturally).
>
> Each module has it's own welcome file ( index.jsp ) which forwards to 
> an action.
>
> Eg:
>
> /myapp/module1/index.jsp:
> ....
> <logic:forward name="login"/>
> ...
>
> The forward tag does not find the global action forward named "login" 
> in the *module's* config file.  However, if I place a global action 
> forward by that name in the *default* config file, it finds it there.
>
> Should the forward tag be aware that it's within a module 
> subdirectory, and use the module's config, or is this not possible 
> since it's not going through the struts action servlet, being a jsp?
>
> What's an alternative that will be module-aware? 


-- 
Eddie Bush





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