Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Linking to wildcard URLs

peterv

2007-08-05



Hi,

Is there a way to make the <s:url> tag generate 'nice' URLs linking to
actions with wildcards in their names?

For example, let's take the following mapping using DefaultActionMapper:

 <action name="galleries/*" method="execute" class="galleryViewer">
   < param name="galleryID">{1}</ param>
   <result>/pages/galleries/GalleryViewer.jsp</result>
 </action>

With this mapping an HTTP request to http://server/galleries/3 invokes the
galleryViewer with the galleryID parameter set to 3. Unfortunately, when I
try to link to this action in a JSP using <s:url>, the URL generated by
Struts isn't the nice "/galleries/3", but the standard
"/galleries?galleryID=3" (which I'm trying to avoid). The JSP code:

 <s:url action="galleries" id="url">
   <s:param name="galleryID">3</s:param>
 </s:url>
 <s:a href="%{url}">View gallery 3</s:a>

How can I make Struts generate 'nice' URLs based on the <action> definitions
in struts.xml?

(Of course I could hardwire the custom URL format into each JSP that links
to the action, but that would be redundant and would take a lot of work to
change the URL structure later.)

Thanks,
Peter

--
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.