---
title: "struts标签bean:define "
author: "小嘴冰凉"
date: "2008-10-08T14:46:14Z"
tags: ["Bean", "Struts", "脚本"]
slug: "struts-bean-define"
draft: false
lastmod: "2009-08-19T19:49:29Z"
id: 250320
url: "https://kdisk-sina-com.iteye.com/blog/250320"
---

```java

<bean:define id="foo" value="This is a new String"/>
<bean:define id="bar" value='<%= "Hello, " + user.getName() %>'/>
<bean:define id="last" scope="session" value='<%= request.getRequestURI() %>'/> 


二是复制一个现有的bean给新的bean：

<bean:define id="foo" name="bar"/> 
<bean:define id="baz" name="bop" type="com.mycompany.MyClass"/> //定义脚本变量的类型，默认为Object 


三是复制一个现有的bean的属性给新的bean：

<bean:define id="bop" name="user" property="role[3].name"/>
<bean:define id="foo" name="bar" property="baz" scope="request" toScope="session"/> 
//toScope属性指新bean的scope，默认为page 

上段代码的意思是把名为bar的bean的baz属性赋值给foo，foo的类型为String(默认)。 

```