在Jsp页面里面将Struts标签所取的值赋给一个字符串

请注意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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值