2006-09-15

webwork学习2 zt

表单数据的获取
1、Action:“Form.java”
--------------------------

import com.opensymphony.xwork.ActionSupport;
import java.util.ArrayList;

public class Form extends ActionSupport{

String name;
int sex;
boolean mem = false;
ArrayList fav = new ArrayList();
String concat;

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public void setSex(int sex) {
this.sex = sex;
}

public int getSex() {
return this.sex;
}

public void setFav(String[] favs) {
for (int i = 0; i < favs.length; ++i) {
this.fav.add(favs[i]);
}
}

public ArrayList getFavs() {
return this.fav;
}

public void setConcat(String concat) {
this.concat = concat;
}

public String getConcat() {
return this.concat;
}

public void setMem(boolean mem) {
this.mem = mem;
}

public boolean getMems() {
return this.mem;
}

public String execute() throws Exception {
if (this.name == null || this.name.equals("")) {
return "input";
}
return "success";
}

}



2、“input.jsp”
--------------------------

<%@page contentType="text/html"%>
<%@page pageEncoding="gbk"%>
<%@ taglib uri="/WEB-INF/webwork.tld" prefix="ww" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>个人资料</title>
</head>
<body>

<h1>请填写你的个人资料</h1>

<form action="Fav.action" name="f" method="post">
姓名:<input type="text" name="name" value=""><br />
性别:<input type="radio" name="sex" value="1" checked="true">男  <input type="radio" name="sex" value="0">女<br />
爱好:
<select size="6" name="fav" multiple="true">
<option value="打球">打球</option>
<option value="听音乐">听音乐</option>
<option value="看电影">看电影</option>
<option value="看书">看书</option>
<option value="跑步">跑步</option>
<option value="爬山">爬山</option>
</select><br />
联系方式:<input type="text" name="concat"><br />
是否党员:<input type="checkbox" name="mem" value="true">
<input type="submit" value="确定"> <input type="reset" value="重置">
</form>
</body>
</html>



3、“success.jsp”
--------------------------

<%@page contentType="text/html"%>
<%@page pageEncoding="gbk"%>
<%@ taglib uri="/WEB-INF/webwork.tld" prefix="ww" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>个人资料</title>
</head>
<body>
<h3>
欢迎您的到来:<ww:property value="name" escape="true" />,以下是您填写的资料:<hr />
性别:<ww:if test="sex == 1">男</ww:if><ww:else>女</ww:else><br />
爱好:
<ul>
<ww:iterator value="favs">
<ww:if test="top == '爬山'">
<li><span style="color:red"><ww:property/> </span></li>
</ww:if>
<ww:else>
<li><ww:property/></li>
</ww:else>
</ww:iterator>
</ul>
<br />
联系方式:<ww:property value="concat" />
<br />
是否党员:<ww:if test="mems == true">是</ww:if><ww:else>否</ww:else>
<br />
<a href="Fav.action">点击此处返回重填</a>
</h3>
</body>
</html>
评论
happly 2007-09-04
交个朋友,您好!!
happly 2007-09-04
发表评论

您还没有登录,请登录后发表评论

inprise_lyj
搜索本博客
最近加入圈子
存档
最新评论
评论排行榜