<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <h2>Registration </h2> <s:form action="register"> <s:textfield name="username" label="Username "/> <s:password name="password" label="Password "/> <s:password name="confirmPassword" label="Confirm Password "/> <s:textfield name="email" label="Email Address " /> <s:textfield name="mobile" label="Mobile Number " /> <p/> <s:submit value="Register"/> <p/> <s:actionerror/> </s:form> </body> </html>
package action; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String username,password,confirmPassword,email,mobile; public String getConfirmPassword() { return confirmPassword; } public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public RegisterAction() { } public String execute() throws Exception { // do the required process return "success"; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name="username"> <field-validator type="requiredstring"> <message>Username is required </message> </field-validator> </field> <field name="password"> <field-validator type="requiredstring"> <message>Password is required </message> </field-validator> <field-validator type="stringlength"> <param name="minLength">5</param> <message>Password must contain at least ${minLength} characters</message> </field-validator> </field> <field name="email"> <field-validator type="email"> <message>Email address is not valid</message> </field-validator> <field-validator type="requiredstring"> <message>Email address is required!</message> </field-validator> </field> <field name="mobile"> <field-validator type="regex"> <param name="expression">^[0-9]{10}$</param> <message>Mobile number must be of 10 digits</message> </field-validator> </field> <validator type="expression"> <param name="expression">password == confirmPassword</param> <message>Password and confirm password do not match!</message> </validator> </validators>
<action name="register" class="action.RegisterAction"> <result name="success">/registered.jsp</result> <result name="input">/register.jsp</result> </action>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Registration Completed</title> </head> <body> Thank you [ <s:property value="username"/>] for registering. </body> </html>