index.jsp 注册页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<s:form action="userAction" method="post">
<s:textfield name="name" label="用户名"></s:textfield>
<s:password name="password" label="密码" ></s:password>
<s:submit value="注册"></s:submit>
<s:reset value="重置"></s:reset>
</s:form>
</body>
</html>
show.jsp 成功跳转页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<s:fielderror></s:fielderror>
<s:property value="name"></s:property>
<s:property value="password"></s:property>
</body>
</html>
struts.xml 配置页面
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<constant name="struts.configuration.xml.reload" value="true"></constant>
<package name="action" extends="struts-default" strict-method-invocation="false">
<action name="userAction" class="com.chenx.action.UserAction">
<result name="input">index.jsp</result>
<result name="success">show.jsp</result>
</action>
</package>
</struts>
UserAction类
package com.chenx.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private static final long serialVersionUID=1L;
private String name;
private String password;
public String execute() throws Exception{
return SUCCESS;
}
public void setName(String name) {
this.name = name;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
}
UserAction-validation.xml 验证配置 注意DOCTYPE的变化 因为改变了网址
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<!-- 验证用户名 -->
<field name="name">
<field-validator type="requiredstring">
<message>请输入用户名</message>
</field-validator>
</field>
<!-- 验证密码 -->
<field name="password">
<field-validator type="requiredstring">
<message>请输入密码</message>
</field-validator>
</field>
</validators>