You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Will Smith <bu...@gmail.com> on 2007/05/17 20:51:43 UTC

Request parameters appended to urls that don't need them.

Hi, I'm new to struts and liking what I've seen so far. I'm building a toy
application to learn the framework (A simple blogging app). I have an action
with a view() method that returns the string "view". What happens is that a
link is clicked to view details about a particular blog, and a request
parameter is sent (get request) to my BlogService action's view method. The
url for a particular blog is created by iterating through a collection
retrieved from the database. The urls for each blog end up looking like
"/BlogService.action!view?id=1" (the number changes depending on which link
was clicked).

My prepare method sees that there is a parameter named "id" and looks up the
info from the database, and populates my blog object. As stated before the
view() method returns "view" and in my struts.xml I have this defined:

<action name="BlogService" class="BlogService">
    <result>blog/Blogs.jsp</result>
    <result name="input">blog/Blog_edit.jsp</result>
    <result name="view">blog/Blog_view.jsp</result>
</action>

<action name="*">
    <result>/{1}.jsp</result>
</action>

So my blog/Blog_view.jsp is the view that is rendered. Everything works as
expected, but I noticed that when the Blog_view view is rendered, my
navigation links now have that request parameter appended to them when the
don't need it. Here's an example of the code I'm using for my navigation:

<li><a href="<s:url action="index" />">Home</a></li>
<li><a href="<s:url action="About" />">About</a></li>

Now before I click a link that takes me to the "Blog_view.jsp", the code
above renders as a link to "/index.action" & "/about.action" which will
really just render "index.jsp" & "about.jsp" since there are no action
classes behind them (setup by the action name="*" in my struts.xml file).

But after I click a link that takes me to the "Blog_view.jsp" the navigation
links are rendered as "/index.action?id=1" & "/about.action?id=1" (the
number changes based on the previously requested id). Now the links still
work, and currently it isn't hurting anything, but I think that maybe I've
gone wrong somewhere, and I'm not too happy about that fact that the request
parameters are sticking around.

Please let me know if I didn't make any sense, or if I need to provide more
detail.
Any help is greatly appreciated.

Thanks,
Will

Re: Request parameters appended to urls that don't need them.

Posted by Dave Newton <ne...@yahoo.com>.
--- Will Smith <bu...@gmail.com> wrote:
> Is this something that is commonly needed?

Actually, I don't really know... Personally I think
defaulting to *not* including params would make more
sense as that is "expected" behavior. 

*shrug*

d.



       
____________________________________________________________________________________Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222

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


Re: Request parameters appended to urls that don't need them.

Posted by Will Smith <bu...@gmail.com>.
On 5/17/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Will Smith <bu...@gmail.com> wrote:
> > Everything works as expected, but I noticed that
> when
> > the Blog_view view is rendered, my navigation links
> > now have that request parameter appended to them
> when
> > the don't need it.
>
> http://struts.apache.org/2.x/docs/url.html
>
> See the includeParams attribute.
>
> http://struts.apache.org/2.x/docs/strutsproperties.html
>
> See the struts.url.includeParams property. You should
> probably set it in your struts.xml file as per:
>
> http://struts.apache.org/2.x/docs/constant-configuration.html
>
> d.


Thanks, that worked out perfect. Is this something that is commonly needed?
When using this, are there any issues I should look out for in the future?
Basically, I'm just trying to make sure I'm using the framework as it was
intended.

Thanks for your help Dave.

Will

Re: Request parameters appended to urls that don't need them.

Posted by Dave Newton <ne...@yahoo.com>.
--- Will Smith <bu...@gmail.com> wrote:
> Everything works as expected, but I noticed that
when
> the Blog_view view is rendered, my navigation links 
> now have that request parameter appended to them
when
> the don't need it. 

http://struts.apache.org/2.x/docs/url.html

See the includeParams attribute.

http://struts.apache.org/2.x/docs/strutsproperties.html

See the struts.url.includeParams property. You should
probably set it in your struts.xml file as per:

http://struts.apache.org/2.x/docs/constant-configuration.html

d.



       
____________________________________________________________________________________Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433

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