1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<s:form action="userAction" name="" method="post" >
<div>
用户名:<s:textfield name="uname"></s:textfield>
</div>
<div>
密码:<s:password name="upwd" ></s:password>
</div>
<div>
性别:<s:radio list="#{1:'男',2:'女'}" name="sex"></s:radio>
</div>
<div>
爱好:
<s:checkboxlist list="#{1:'看美女',2:'吃饭',3:'睡觉',4:'睡觉'}" name="hobby"></s:checkboxlist>
</div>
<div>
城市:
<s:select list="#{'看美女':'看美女','吃饭':'吃饭','睡觉':'睡觉','睡觉':'睡觉'}" name="city"></s:select>
</div>
<div>
介绍:
<s:textarea name="intro" cols="30" rows="5"></s:textarea>
</div>
<div>
靓照:
<s:file name="img"></s:file>
</div>
<div>
<s:submit value=" 提 交 "></s:submit>
<s:reset value=" 重 置 "></s:reset>
</div>
<s:token></s:token><%-- 防止表单重复提交,这句话很重要--%>
</s:form>
</body>
</html>
2.struts.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<package name="test" namespace="" extends="struts-default">
<interceptors>
<interceptor-stack name="myinterstack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="token"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="userAction" class="com.action.UserAction">
<interceptor-ref name="myinterstack"></interceptor-ref>
<result name="success">/success.jsp</result>
<result name="invalid.token">/index.jsp</result><!-- 这里invalid.token的意思是当表单重复提交之后 -->
</action>
</package>
</struts>