请注意19行到25行
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="struts2"%>
<!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=utf-8">
<title>西安Java培训西安小升初</title>
</head>
<body>
<h2>预览页面</h2>
<font color="green"> <b>名字:<struts2:property
value="userName" /></b><br> <b>Roll No. : <struts2:property
value="roll" /></b><br> <b>Section : <struts2:property
value="section" /></b><br> <b>Std/Class : <struts2:property
value="stdClass" /></b><br>
</font>
<p>
<%
String test;
test = (String) request.getAttribute("userName");
//不是说用了struts就不需要java代码了
//这样做增加了灵活性,比如治理中文乱码,可以细化到字节级别
out.println(test);
%>
</p>
</body>
</html>
package sample;
public class MyExample {
private String userName;
private String roll;
private String section;
private String stdClass;
public String preview() throws Exception {
return "preview";
}
public String getUserName() {
return this.userName;
}
public void setUserName(String argUserName) {
userName = argUserName;
}
public String getRoll() {
return this.roll;
}
public void setRoll(String argRoll) {
roll = argRoll;
}
public String getSection() {
return this.section;
}
public void setSection(String argSection) {
section = argSection;
}
public String getStdClass() {
return this.stdClass;
}
public void setStdClass(String argStdClass) {
stdClass = argStdClass;
}
}
<struts2:form method="post" action="myexample" namespace="/sample">
<table>
<tr>
<td><struts2:textfield name="userName" label="姓名 " /></td>
</tr>
<tr>
<struts2:textfield name="roll" label="Roll " />
</td>
</tr>
<tr>
<td><struts2:textfield name="section" label="Section " /></td>
</tr>
<tr>
<struts2:textfield name="stdClass" label="Std/Class " />
</td>
</tr>
<tr>
<td colspan="2"><struts2:submit value="注册" /></td>
</tr>
</table>
</struts2:form>
参考: http://www.techienjoy.com/Struts2-example-steps-Tag-usage.php
源代码:http://pan.baidu.com/share/link?shareid=465109&uk=3878681452