---
title: "Struts1.2.4学习心得!(－)"
author: "fanjava"
date: "2004-09-25T08:39:00Z"
tags: []
slug: "struts1-2-4"
draft: false
lastmod: "2004-09-25T08:39:00Z"
id: 601893
url: "https://fanjava.iteye.com/blog/601893"
---

第一次学习:

1.直接转发配置，在struts-config.xml 可以直接将请求转到指定位置：  
如：&lt;action path="/welcome" forward="/index.html" /&gt;  
当在网页上打开 welcome.do时，自动跳到index.html

2.cookie的使用:  
在JSP网页头部增加一句：&lt;%@ taglib uri="/tags/struts-bean" prefix="bean" %&gt;  
用下面的代码新建cookie.  
&lt; bean : cookie id="sess" name="JSESSIONID" value="JSESSIONID-IS-UNDEFINED" / &gt;  
取cookie的值：  
(1)&lt; jsp:getProperty name="sess" property="comment" /&gt;  
这种取法，当comment为空时，显示null  
(2)&lt; bean:write name="sess" property="comment" /&gt;  
这种取法，当comment为空时,什么也不显示

3.int,float,string等数据类型在网页上的显示:

设有一个TestBean的BEAN的函数返回多种数据类型． 用下面语句取 bean对象．  
&lt;jsp:useBean id="test1" scope="page" class="org.apache.struts.webapp.exercise.TestBean" /&gt;  
用下面语句定义返回的各种数据类型的值：

**java代码:**

1  
2&lt; bean:define id="test1\_boolean" name="test1" property="booleanProperty" /&gt;  
3 &lt; bean:define id="test1\_double" name="test1" property="doubleProperty" /&gt;  
4 &lt; bean:define id="test1\_float" name="test1" property="floatProperty" /&gt;  
5&lt; bean:define id="test1\_int" name="test1" property="intProperty" /&gt;  
6 &lt; bean:define id="test1\_long" name="test1" property="longProperty" /&gt;  
7 &lt; bean:define id="test1\_short" name="test1" property="shortProperty" /&gt;  
8&lt; bean:define id="test1\_string" name="test1" property="stringProperty" /&gt;  
9

用下面的方法显示值：

**java代码:**

1  
2&lt;%= test1\_boolean %&gt;  
3&lt;%= test1\_double %&gt;  
4 &lt;%= test1\_string %&gt;  
5................  
6