struts2标签的使用(一)
来源:互联网 发布:沐林视觉美工学费贵吗 编辑:程序博客网 时间:2024/04/29 16:14
网上铺天盖地的有很多的例子,手册之类,这里引用一个我初学时做的一个例子
TestAction中:
public class TestAction extends ActionSupport {
public String test1() {
Product product = new Product();
product.setProdId(new Long(112233));
ProdSpec prodSpec = new ProdSpec();
prodSpec.setProdSpecId(new Integer("379"));
prodSpec.setName("CDMA");
product.setProdSpec(prodSpec);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("myName", "zhuxia");
//增加一个地址
List<Prod2Addr> list = new ArrayList<Prod2Addr>();
Prod2Addr addr1 = new Prod2Addr();
addr1.setProdId(new Long(111));
addr1.setAddressId(new Long(1233));
addr1.setReasonCd(new Integer(3));
Prod2LocationReason p1 = new Prod2LocationReason();
p1.setReasonCd(new Integer(3));
p1.setName("install address");
addr1.setProd2LocationReason(p1);
addr1.setAddressDesc("Nan Jing Road");
list.add(addr1);
Prod2Addr addr2 = new Prod2Addr();
addr2.setProdId(new Long(111));
addr2.setAddressId(new Long(1233));
addr2.setReasonCd(new Integer(3));
addr2.setAddressDesc("Shang Hai Road");
addr2.setProd2LocationReason(p1);
list.add(addr2);
product.setProd2Addrs(list);
request.setAttribute("product", product);
return "test1";
}
}
test1 对应test1.jsp页面,内容如下:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<s:set name="name" value="#request.myName"/>
1: request.myName value1112233444<br/>
<s:property value="#request.myName"/><br/>
the name is : <s:property value="#name"/> <br/>
<br/>
2: test if<br/>
<s:set name="prodSpecName" value="#request.product.prodSpec.name"/>
the prodSPecName is: <s:property value="#prodSpecName"/>
<br>
test another example
<s:set name="prodSpec" value="#request.product.prodSpec"/>
<s:if test="#prodSpec != null">
prodSpecId is:<s:property value="#prodSpec.prodSpecId"/><br/>
prodSpecName is: <s:property value="#prodSpec.name"/>
</s:if>
test another example: the context can not be seen <br/>
<s:set name="area" value="#request.product.area"/>
<s:if test="#area != null">
areaId: <s:property value="#area.areaId"/><br/>
areaName:<s:property value="#area.name"/> <br/>
</s:if>
<s:else>
the product.area is null
</s:else>
<br/>
<br/>
3:iterator <br/>
<s:set name="prod2Addrs" value="#request.product.prod2Addrs"/>
<s:iterator value="#prod2Addrs" status="prod2Addr">
<br/>
<br/>
addressDesc : <s:property value="addressDesc"/><br/>
prod2Addr.reasonName11 : <s:property value="prod2LocationReason.name"/><br/>
location : <s:set name="prod2LocationReason" value="prod2LocationReason"/><br/>
reasonName : <s:property value="#prod2LocationReason.name"/> <br/>
prod2Addr.reasonName22 : <s:property value="prod2LocationReason.name"/><br/>
</s:iterator>
</body>
</html
运行结果:
1: request.myName value1112233444
zhuxia
the name is : zhuxia
2: test if
the prodSPecName is: CDMA
test another example prodSpecId is:379
prodSpecName is: CDMA test another example: the context can not be seen
the product.area is null
3:iterator
addressDesc : Nan Jing Road
prod2Addr.reasonName11 : install address
location :
reasonName : install address
prod2Addr.reasonName22 : install address
addressDesc : Shang Hai Road
prod2Addr.reasonName11 : install address
location :
reasonName : install address
prod2Addr.reasonName22 : install address
- struts2标签的使用(一)
- 使用Struts2的标签库(一)
- Struts2标签使用一特例
- struts2标签的使用
- Struts2 标签的使用
- struts2标签的使用!
- Struts2标签的使用
- Struts2标签的使用
- Struts2 标签的使用
- struts2标签的使用
- Struts2的标签库(一)之控制标签
- struts2的常用标签(一)
- 使用struts2标签上传用户头像(一)
- Struts2.X标签(一)
- struts2标签相关(一)
- struts2常用标签(一)
- struts2标签解析(一)
- Struts2 标签库 UI标签的使用
- 做程序员出路在哪里?
- 6120c ucweb 7.0 正式版下载 SISX 免签名
- C++各大有名库的介绍
- 有趣的C语言问题 测试你对C语言的熟悉程度
- 给未来的电子通信工程师
- struts2标签的使用(一)
- 深入PVM
- servlet生命周期
- vc网络编程入门
- java.security.*包下MessageDigest类的简单应用 MD5加密
- Customize your own Silverlight control
- 英语谚语一则(For want of a nail the shoe was lost)
- 敏捷开发
- don’t know how to make ‘TargetCompilePass’