Struts2 数据标签(四)s:param标签的三种赋值方法
1.新建JavaBean的实例:
package com.wl.control.Bean;public class UserInfo { private String name; private int weight; private String usernameHasValue="我是张三"; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getWeight() { return weight; } public void setWeight(int weight) { this.weight = weight; } public String getUsernameHasValue() { return usernameHasValue; } public void setUsernameHasValue(String usernameHasValue) { this.usernameHasValue = usernameHasValue; }}
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <body> 第一种写法:<br/> <s:bean name="com.wl.control.Bean.UserInfo" var="userInfo1"> <s:param name="name">张三</s:param> <s:property value="#userInfo1.name"/> </s:bean> <br/> 第二种写法:<br/> <s:bean name="com.wl.control.Bean.UserInfo" var="userInfo2"> <s:param name="name" value="张三"></s:param> <s:property value="#userInfo1.name"/> </s:bean> <br/> 第三种写法:<br/> <s:bean name="com.wl.control.Bean.UserInfo" var="userInfo3"> <s:param name="name" value="usernameHasValue"></s:param> <s:property value="#userInfo1.usernameHasValue"/> </s:bean> </body></html>