You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Trentham <TT...@hand.com> on 2001/07/12 18:11:27 UTC

Extra path info and action mappings

I'm trying to use extra path info as a way to pass parameters to my actions.
I changed the mapping from the default *.do to something like /execute/*.
This works fine except that if I add extra information and try to submit, I
get a 400 error telling me that I have submitted an invalid path.

For example, I had a mapping called show.do which has now been changed to
/execute/show. Now, if I try to submit /execute/show/user, expecting to have
"user" passed to the show servlet as part of the extra path info accessed by
request.getPathInfo(), I get the invalid path error. It works if I add
another action mapping in the struts-config.xml that looks like this

<action path="/show/user" type="com.mypackage.ShowAction">
 <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
</action>

This means that I have to have a separate action mapping for each different
thing that I'd like an action to perform even though they're using the same
action.

I was expecting to be able to have something like this in the
struts-config.xml:

<action path="/show" type="com.mypackage.ShowAction">
 <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
 <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
</action>

Instead, I have to do this:

<action path="/show/user" type="com.mypackage.ShowAction">
 <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
</action>

<action path="/show/group" type="com.mypackage.ShowAction">
 <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
</action>

The idea behind this is that I can have one action that basically just
passes through the extra path info and forwards to the correct page based on
that info.

Is there another way to set this up so that you don't have to have an action
mapping that matches the extra path info?

Thanks.

Tim

--------------------------------
Tim Trentham
ttrentham@hand.com


Re: Extra path info and action mappings

Posted by Ted Husted <hu...@apache.org>.
Here's another approach to followup my earlier reply. 

ActionMappings could be extended so that if an exact match was not
found, and the path contained interior slashes, it would start trimming
the "directories" from right to left. So given /package/action/info it
would first try 

/package/action/info

if no match was found, before returning, it would try

/package/action

if that matched, it would update the mapping with the "info" and return
normally. 

The info could either be placed in the existing "parameters" property,
or ActionMapping could be extended with an "extra" property. Besides
getExtra(), there might also be getExtraCount and getExtras() methods to
help retrieve multiple parameters.

(Which also suggests that maybe we should have getParameterCount() and
getParameters() methods so that the parameter property could
conveniently store more than one parameter.)

-T.

Re: Extra path info and action mappings

Posted by Ted Husted <hu...@apache.org>.
My recollection is that Web servers try each component on a path to see
if it is a file or directory, stop when a file is found, and pass the
rest as "extra information". Correct me if that is not what we are
talking about.

With query strings, you'd just have something like "/show?user" or
"/show?group", and Struts would render that as "/execute/show?group" or
"/show.do?group" -- but I take it that the point is that query strings
aren't an option here (because of a proxy server or something). 

As it stands, I don't believe the ActionMappings used by the
ActionController can distinguish between URI's with extra information
and those without. Since the Mappings are virtual, there's no way to
tell where the "file path" ends and the extra information begins. 

It's important to note that show in the example is not a Servlet -- it's
a multithreaded Action that is managed by the single ActionServlet in
your application. So, we would need a way for the Controller to pass
extra information along to the Action, perhaps bundled as request
parameters. This way /file/extra/information and /file?extra&information
would be equivalent.

I'm not sure if this would be a good idea or not, but one thing would be
to allow wildcards in Action paths, so that /show/* could match any URI
beginning with show, with the remainder being placed in the request as
parameters. 

Also without stating an opinion, being able to specify */display as an
actin path could address Jonathan's question from the otehr day.

In either case, the ActionMapping could first be checked for an exact
match, with the wildcards being checked when an exact match wasn't
found. 


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

Tim Trentham wrote:
> 
> I'm trying to use extra path info as a way to pass parameters to my actions.
> I changed the mapping from the default *.do to something like /execute/*.
> This works fine except that if I add extra information and try to submit, I
> get a 400 error telling me that I have submitted an invalid path.
> 
> For example, I had a mapping called show.do which has now been changed to
> /execute/show. Now, if I try to submit /execute/show/user, expecting to have
> "user" passed to the show servlet as part of the extra path info accessed by
> request.getPathInfo(), I get the invalid path error. It works if I add
> another action mapping in the struts-config.xml that looks like this
> 
> <action path="/show/user" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
> </action>
> 
> This means that I have to have a separate action mapping for each different
> thing that I'd like an action to perform even though they're using the same
> action.
> 
> I was expecting to be able to have something like this in the
> struts-config.xml:
> 
> <action path="/show" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
>  <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
> </action>
> 
> Instead, I have to do this:
> 
> <action path="/show/user" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
> </action>
> 
> <action path="/show/group" type="com.mypackage.ShowAction">
>  <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
> </action>
> 
> The idea behind this is that I can have one action that basically just
> passes through the extra path info and forwards to the correct page based on
> that info.
> 
> Is there another way to set this up so that you don't have to have an action
> mapping that matches the extra path info?
> 
> Thanks.
> 
> Tim

Re: Extra path info and action mappings

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Tim,

What servlet container are you trying this on?  Your assumptions about
what is *supposed* to work are correct (with one minor correction -- the
extra path info will be "/user" instead of "user"), so it could be either
a bug in Struts or a bug in the servlet container you are running on.

Craig McClanahan


On Thu, 12 Jul 2001, Tim Trentham wrote:

> I'm trying to use extra path info as a way to pass parameters to my actions.
> I changed the mapping from the default *.do to something like /execute/*.
> This works fine except that if I add extra information and try to submit, I
> get a 400 error telling me that I have submitted an invalid path.
> 
> For example, I had a mapping called show.do which has now been changed to
> /execute/show. Now, if I try to submit /execute/show/user, expecting to have
> "user" passed to the show servlet as part of the extra path info accessed by
> request.getPathInfo(), I get the invalid path error. It works if I add
> another action mapping in the struts-config.xml that looks like this
> 
> <action path="/show/user" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
> </action>
> 
> This means that I have to have a separate action mapping for each different
> thing that I'd like an action to perform even though they're using the same
> action.
> 
> I was expecting to be able to have something like this in the
> struts-config.xml:
> 
> <action path="/show" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
>  <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
> </action>
> 
> Instead, I have to do this:
> 
> <action path="/show/user" type="com.mypackage.ShowAction">
>  <forward name="/show/user" path="/WEB-INF/jsp/user.jsp"/>
> </action>
> 
> <action path="/show/group" type="com.mypackage.ShowAction">
>  <forward name="/show/group" path="/WEB-INF/jsp/group.jsp"/>
> </action>
> 
> The idea behind this is that I can have one action that basically just
> passes through the extra path info and forwards to the correct page based on
> that info.
> 
> Is there another way to set this up so that you don't have to have an action
> mapping that matches the extra path info?
> 
> Thanks.
> 
> Tim
> 
> --------------------------------
> Tim Trentham
> ttrentham@hand.com
> 
>