Using tags in Struts(II)

9 January 2008

This post is a continuation of Using tags in Struts(I), so please go through it before this one.

Now let see how the code works.

“%{url}” will be evaluated to the url defined with the s:url tag. On the Welcome and HelloWorld pages, we use two different Struts tags to create links. We create

1. Resource links

First, in the head element, we use the url tag to inject a page reference into the HTML link tag.

<link href="<s:url value="/css/tutorial.css"/>" 
  rel="stylesheet" type="text/css"/>

Note that the reference is absolute. We can move the page around without worrying about resolving relative references.

2. Direct links

In the “Commands” section, we use the url link again, to inject a reference to an Action.

<li><a href="<s:url action="Register"/>">Register</a></li>

When the link is rendered, the tag will automatically append the appropriate extension, so that we do not need to embed that fact all over the application.

The tag will also URL-encode the link with the Java session ID, if needed, so that the Java session can be retained across requests.

3. Links with parameters

Finally, in the Languages section on the HelloWorld page, we use the url tag along with the param and a tags to create a link with request parameters.

<s:url id="url" action="Welcome">
  <s:param name="request_locale">en</s:param>
</s:url>
<s:a href="%{url}">English</s:a>

The param tag will add the parameter “?request_locale=en” to the Welcome Action URL, and store it under the name “url”. The a tag then injects the “url” reference into the hyperlink.

del.icio.us:Using tags in Struts(II)  digg:Using tags in Struts(II)  spurl:Using tags in Struts(II)  wists:Using tags in Struts(II)  simpy:Using tags in Struts(II)  newsvine:Using tags in Struts(II)  blinklist:Using tags in Struts(II)  furl:Using tags in Struts(II)  reddit:Using tags in Struts(II)  fark:Using tags in Struts(II)  blogmarks:Using tags in Struts(II)  Y!:Using tags in Struts(II)  smarking:Using tags in Struts(II)  magnolia:Using tags in Struts(II)  segnalo:Using tags in Struts(II)  gifttagging:Using tags in Struts(II)

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Using tags in Struts(II)

Leave a Reply