Struts标签-bean:write几个属性举例

Struts标签-bean:write几个属性举例2009-04-07 17:24TiglibAction中的代码:

package com.yulin.struts;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class TiglibAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//输出普通字符串
request.setAttribute("string", "输出普通string");
//输出html文件
request.setAttribute("html", "<font color='red'>输出html文件</font>");
//输出date
request.setAttribute("date", new Date());
//输出number
request.setAttribute("number", 12345.67);
//输出User
Group g = new Group();
g.setName("China");
User u = new User();
u.setUsername("LinZhang");
u.setAge(23);
u.setGroup(g);
request.setAttribute("user", u);

return mapping.findForward("success");
}

}

User类代码:

package com.yulin.struts;

public class User {
private String username;
private int age;
private Group group;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
}

Group类代码:

package com.yulin.struts;

public class Group {
private String name;

public String getName() {
return name;
}

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


对应的jsp页面代码:

<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<!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>测试Beanwrite标签</title>
</head>
<body>
<li>测试Beanwrite标签</li>
<hr>
普通string输出:<br>
string(jsp):<%=request.getAttribute("string") %><br>
string(taglib):<bean:write name="string"/>
<hr>
输出html文件:<br>
html(default):<bean:write name="html"/><br>
html(filter="true"):<bean:write name="html" filter="true"/><br>
html(filter="false"):<bean:write name="html" filter="false"/><br>
<hr>
输出date:<br>
date(default):<bean:write name="date"/><br>
date(format="yy-MM-dd HH:mm:ss"):<bean:write name="date" format="yy-MM-dd HH:mm:ss"/><br>
<hr>
输出number:<br>
number(default):<bean:write name="number"/><br>
number(format="###,###.###"):<bean:write name="number" format="###,###.###"/><br>
number(format="###,###.000"):<bean:write name="number" format="###,###.000"/><br>
<hr>
输出User:<br>
Name:<input type="text" value=" <bean:write name="user" property="username"/> " ><br>
Age:<input type="text" value=" <bean:write name="user" property="age"/> "><br>
Group:<input type="text" value=" <bean:write name="user" property="group.name"/> "><br>
</body>
</html>

浏览器显示出来的效果:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值