现在的位置: 首页 > 综合 > 正文

Struts1.2.4学习心得!(-)

2013年08月02日 ⁄ 综合 ⁄ 共 1217字 ⁄ 字号 评论关闭
第一次学习:

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

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

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

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

java代码: 
 1 
 2 < bean:define id="test1_boolean" name="test1" property="booleanProperty" />
 3  < bean:define id="test1_double" name="test1" property="doubleProperty" />
 4  < bean:define id="test1_float" name="test1" property="floatProperty" />
 5 < bean:define id="test1_int" name="test1" property="intProperty" />
 6  < bean:define id="test1_long" name="test1" property="longProperty" />
 7  < bean:define id="test1_short" name="test1" property="shortProperty" />
 8 < bean:define id="test1_string" name="test1" property="stringProperty" />
 9 


用下面的方法显示值:

java代码: 
 1 
 2 <%= test1_boolean %>
 3 <%= test1_double %>
 4  <%= test1_string %>
 5 ................
 6 

抱歉!评论已关闭.