Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Panel

The Code

Code Block
htmlhtml
titleWelcome.jsp
borderStylesolid
html
<%@ 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>
</body>
</html>

Another common use case is using a link to change locales. On the HelloWorld page, let's add links to change the user's locale and to display a message from the application resources.

Panel

html
Code Block
html
borderSytlesolid
titleHelloWorld.jsp
html
<body>
<h2><s:property value="message"/></h2>

<h3>Languages</h3>
<ul>
    <li>
        <s:url var="url" action="Welcome">
            <s:param name="request_locale">en</s:param>
        </s:url>
        <s:a href="%{url}">English</s:a>
    </li>
    <li>
        <s:url var="url" action="Welcome">
            <s:param name="request_locale">es</s:param>
        </s:url>
        <s:a href="%{url}">Espanol</s:a>
    </li>
</ul>
</body>

...

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

xml
Code Block
xml
titlestruts.xml
borderStylesolid
xml
<action name="*" >
  <result>/{1}.jsp</result>
</action>

...

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

Panel

The Code

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

...