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.

Panel

Image Added

The 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>

...

Most applications will use several data entry forms. The Struts tags make creating input forms easy.

Panel

Image Added

The Code

Code Block
html
html
titleLogon.jsp
borderStylesolid
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
  <title>Logon</title>
</head>
<body>
<s:form action="Logon">
  <s:textfield label="User Name" name="username"/>
  <s:password label="Password" name="password" showPassword="true"/>
  <s:submit/>
</s:form>
</body>
</html>

...