1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>
<form action="user.action" method="post" >
用户名:<input type="text" name="list[0]" id="uname"/></br>
密码:<input type="text" name="list[1]" id="pwd"/></br>
<input type="submit" value="提交"/>
</form>
</body>
</html>
2.javabean类
package com.bean;
public class testbean {
private String uname;
private String pwd;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
3.action类
package com.action;
import java.util.List;
import com.bean.testbean;
import com.opensymphony.xwork2.ActionSupport;
public class testaction extends ActionSupport{
private List<String> list;
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public String dis(){
for(int i=0;i<list.size();i++){
System.out.println("========="+list.get(i));
}
return "show";
}
}
4.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>
<package name="default" extends="struts-default" namespace="/">
<!-- <action name="user" class="com.action.testaction">
<result name="ok">/index.jsp</result>
</action>-->
<action name="user" class="com.action.testaction" method="dis">
<result name="show">/index.jsp</result>
</action>
</package>
</struts>