Versions Compared

Key

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

...

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>

How the Code Works

On the Welcome page, we use two different Struts tags to create links. We create

...

As we create the application, we will often want to go directly to a page. To make prototyping easy, we can change the Welcome entry to a wilcard mapping.

The Code

Code Block
xml
xml
titlestruts.xml
borderStylesolid
<action name="*" >
  <result>/tutorial/(1).jsp</result>
</action>

How the Code Works

If no other mapping matches, the framework will

...

  • The JSP engine reads the taglib reference at the top of the page and loads the Struts Tags for use with this page under the prefix "s".
  • The Struts Tags – textfield, password, and submit – each emit the appropriate label and control type.

...

What to Remember

The hardest part of writing a web application can be coding the pages. The framework makes coding pages easier by providing a set of custom tags. The Struts Tags can access dynamic data provided by the fraemwork, and framework. Tags reduce the amount of markup needed to create a page.

...