THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
As before, we set everything up in four steps: create the form, create the action, register the action, and create the landing page (or in this case, pages).
1. Create the form
Paste this html into \[ webapp\]/page03.jsp: Wiki Markup
Code Block | ||||
---|---|---|---|---|
| ||||
<html> <head> <title>A simple form with data</title> </head> <body> <p>What is your name?</p> <form action="form03.action" method="post"> <p><input type="text" name="yourName"></p> <p><input type="submit" value="Submit your name." /></p> </form> </body> </html> |
2. Create the form action
...
Paste this code into \[ src\]/lessons/Form03Action.java:
Code Block | ||||
---|---|---|---|---|
| ||||
package lessons; import com.opensymphony.xwork.ActionSupport; public class Form03Action extends ActionSupport { String yourName; public void setYourName(String p_yourName) { yourName = p_yourName; } public String getYourName() { return yourName; } public String execute() throws Exception { if (yourName == null || yourName.length() == 0) return ERROR; else return SUCCESS; } } |
3. Register the action in xwork.xml:
Edit \[ webapp\]/WEB-INF/classes/xwork.xml: Wiki Markup
Code Block | ||||
---|---|---|---|---|
| ||||
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd"> <xwork> <!-- Include webwork defaults (from WebWork JAR). --> <include file="webwork-default.xml" /> <!-- Configuration for the default package. --> <package name="default" extends="webwork-default"> <!-- Default interceptor stack. --> <default-interceptor-ref name="defaultStack" /> <!-- 02 --> <action name="form02" class="lessons.Form02Action"> <result name="success" type="dispatcher">page02-success.jsp</result> </action> <!-- 03 --> <action name="form03" class="lessons.Form03Action"> <result name="success" type="dispatcher">page03-success.jsp</result> <result name="error" type="dispatcher">page03-error.jsp</result> </action> </package> </xwork> |
4. Create the success and error pages
...
Create \[ webapp\]/page03-success.jsp:
Code Block | ||||
---|---|---|---|---|
| ||||
<%@ taglib uri="webwork" prefix="ww" %> <html> <head> <title>Success page for form with data</title> </head> <body> Hello, <ww:property value="yourName" />! </body> </html> |
Create \[ webapp\]/page03-error.jsp: Wiki Markup
Code Block | ||||
---|---|---|---|---|
| ||||
<html> <head> <title>Error page for form with data</title> </head> <body> Hmm, you don't seem to have entered a name. Go back and try again please. </body> </html> |
...