Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A very common use cases in web applications is linking to other pages. Now that we know Struts is up and running, let's add a Welcome page with links to other actions.

Page Code

Code Block
html
html
titleWelcome.jsp
borderStylesolid
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Welcome</title>
    <link href="<s:url value="/css/tutorial.css"/>" rel="stylesheet"
          type="text/css"/>
</head>
<body>
<h3>Commands</h3>
<ul>
    <li><a href="<s:url action="Register"/>">Register</a></li>
    <li><a href="<s:url action="Logon"/>">Sign On</a></li>
</ul>

<h3>Languages</h3>
<ul>
    <li>
        <s:url id="url" action="Welcome">
            <s:param name="request_locale">en</s:param>
        </s:url>
        <s:a href="%{url}">English</s:a>
    </li>
    <li>
        <s:url id="url" action="Welcome">
            <s:param name="request_locale">ja</s:param>
        </s:url>
        <s:a href="%{url}">Japanese</s:a>
    </li>
</ul>

</body>
</html>

...

The framework provides an array of tags, ranging from the mundane to the insane. See the Tag Developers Guide for details.

Mapping Code

Since the Welcome page is simple, we don't need an Action. But, we should still add a mapping, so that we can use use an action URI. If we link only to actions, and never to pages, then it's easy to add a Action class later.

<action name="Welcome" >
<result>/tutorial/Welcome.jsp</result>
</action>

Next

Onward to Coding Actions

Prev

Return to Hello World