...
On the Welcome page, we use two different Struts tags to create links.
Resource links
First, in the head element, we use the url
tag to inject a page reference into the HTML link
tag.
...
Note that the reference is absolute. We can move the page around without worrying about resolving relative references.
Direct links
In the "Commands" section, we use the url
link again, to inject a reference to an Action.
...
The tag will also URL-encode the link with the Java session ID, if needed, so that the Java session can be retained accross requests.
Links with parameters
Finally, in the Languages section, we use the url
tag along with the param
and a
tags to create a link with request parameters.
...
Since the Welcome page is simplenothing but links, we don't need an Action class. 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.
...
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.
Code Block |
---|
<action name="*" >
<result>/tutorial/(1).jsp</result>
</action>
|
If no other mapping matches, the framework will match "Welcome" to the asterisk, and substitute "Welcome" for any "{1}" tokens in the mapping. Likewise, if there is a link to a "Logon" is matchedaction, and nothing else matches, then the "/Logon.jsp" page is returned instead.
Wildcard mappings let you create your own conventions, so that you can avoid redundant configuration. The first mapping that matches a request wins.
Data Entry Forms
Most applications will use several data entry forms. The Struts tags include a full set of form tags, that make creating input forms easy.
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<%@ 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> |
How The Code Works
- 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, attaching a HTML label attribute, whenever it can.
...
Next
...
Onward to Coding Actions
...
Prev
...
Next | Onward to Coding Actions |
---|---|
Prev | Return to Hello World |