...
Panel |
---|
|
The Code
Code Block |
---|
| html | html |
---|
title | Welcome.jsp |
---|
borderStyle | solid |
---|
| 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 |
---|
|
Code Block |
html |
---|
| html |
---|
borderSytle | solid |
---|
title | HelloWorld.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
Code Block |
xml |
---|
| xml |
---|
title | struts.xml |
---|
borderStyle | solid |
---|
| 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
Code Block |
html |
---|
| html |
---|
title | Logon.jsp |
---|
borderStyle | solid |
---|
| 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>
|
...