??xml version="1.0" encoding="utf-8" standalone="yes"?>久久99久久99精品免视看婷婷,国产精品一区二区三区www,日本中文字幕视频一区http://www.aygfsteel.com/kook/category/15630.htmlzh-cnFri, 02 Mar 2007 03:11:31 GMTFri, 02 Mar 2007 03:11:31 GMT60Validator验证框架http://www.aygfsteel.com/kook/articles/71821.htmlkookkookMon, 25 Sep 2006 12:50:00 GMThttp://www.aygfsteel.com/kook/articles/71821.htmlhttp://www.aygfsteel.com/kook/comments/71821.htmlhttp://www.aygfsteel.com/kook/articles/71821.html#Feedback0http://www.aygfsteel.com/kook/comments/commentRss/71821.htmlhttp://www.aygfsteel.com/kook/services/trackbacks/71821.htmlStruts1.2中创建验证框架的步骤Q?br />
1、在struts-config.xml文g中添加下列内容:
< plug - in className = " org.apache.struts.validator.ValidatorPlugIn " >
        
< set - property property = " pathnames "  value = " /WEB-INF/validator-rules.xml,
                                                                  /WEB-INF/validation.xml
"   />

</ plug - in >

注意Q这些内容必L?lt;message-resources>元素之后。该规则是由
"
http://struts.apache.org/dtds/struts-config_1_2.dtd "文g制定的?br />
2、创建相关的lgQ?br />
Z实验的目的,我依ơ创?个ActionFormc,一个JSPQ一个Actionc,以下是他们在struts-config.xml中的配置信息Q?br />
 1 <form-beans >
 2     <form-bean name="DVForm" type="org.apache.struts.validator.DynaValidatorForm">
 3       <form-property name="name" type="java.lang.String" />
 4     </form-bean>
 5     <form-bean name="DVAForm" type="org.apache.struts.validator.DynaValidatorActionForm">
 6       <form-property name="name" type="java.lang.String" />
 7     </form-bean>
 8     <form-bean name="VForm" type="com.kook.struts.form.HahaForm" />
 9     <form-bean name="VAForm" type="com.kook.struts.form.HohoForm" />
10   </form-beans>
11 
12   <global-exceptions />
13   <global-forwards />
14   <action-mappings >
15     < action
16       attribute="DVForm"

17       input="/form/index.jsp"
18       name="DVForm"
19       path="/index"
20       scope="request"
21       type="com.kook.struts.action.IndexAction" />
22   </action-mappings>

其中
<form-bean name="VForm" type="com.kook.struts.form.HahaForm" />是ValidatorFormcȝ子类
<form-bean name="VAForm" type="com.kook.struts.form.HohoForm" />是ValidatorActionFormcȝ子类

下面是JSP面代码Q?br />
1 <html:form action="/index" onsubmit="return validateDVForm(this)">
2             name : <html:text property="name"/><html:errors property="name"/><br/>
3             <html:submit/>
4  </html:form>
5  <html:javascript formName="DVForm"/>

因ؓ只是做表单验证,actioncd以不用涉及,因此不列出actioncȝ代码啦!

3、删除name="VForm" 和name="VAForm"的ActionForm中的validateҎ?br />
因ؓq两个类不是动态的验证c,在用向导生成代码的时候会自动覆盖父类的validateҎ。如果不删除的话Q根据类的多态性原理,会调用他们生成的validateҎQ而不调用他们父类的该Ҏ。但是,实际上,是他们父cȝvalidateҎ调用了validator框架的验证方法,因此我们没有必要再去重写他的q个Ҏ。同时也要记得删除,因ؓ向导生成的是I实玎ͼ不删除的话,起不到验证作用。切记切讎ͼQ!曄在这吃啊担子_Q?

观察以上代码不难发现Q表单中只有一个文本框Q因此实验也是对q个文本框进行验证?br />
4、创定义的验证文件validation.xmlQ主要内容如下所C:
 1 <form-validation>     
 2     <formset>

 3         <form name="DVForm">
 4             <field property="name" depends="required">
 5                 
 6                 <arg0 name="required" key="lable.name"/>
 7             </field>
 8         </form>
 9     </formset>
10 </form-validation>

其中key="lable.name "在资源文件中对应的内容ؓQlable.name=nameQ因此,当文本框中没有输入Q何信息而提交的时候,会反馈一条name is required.的信息?br />
下面开始实验,
实验的目的是Q依ơ?U验证Form来实现表单的验证功能Q?br />他们分别是:DynaValidatorFormQDynaValidatorActionFormQValidatorFormQValidatorActionForm。这也是前面Z么要创徏4个ActionForm的目的,详细配置信息见前面struts-config.xml
而JSP面只有一个,是配置文g中的input="/form/index.jsp
"

实验一Q由DynaValidatorForm的子cDVForm来验?br />


validation.xml的内容ؓQ?br />
 1 <form-validation>     
 2     <formset>

 3         <form name="DVForm">
 4             <field property="name" depends="required">
 5                 
 6                 <arg0 name="required" key="lable.name"/>
 7             </field>
 8         </form>
 9     </formset>
10 </form-validation>

struts-config.xml的内容ؓQ?br />
15     < action
16       attribute="DVForm"

17       input="/form/index.jsp"
18       name="DVForm"
19       path="/index"
20       scope="request"
21       type="com.kook.struts.action.IndexAction" />
22   </action-mappings>

/form/index.jsp的主要内容ؓQ?br />
1         <html:javascript formName="DVForm"/>
2         <html:form action="/index" onsubmit="return validateDVForm(this)">

<
html:javascript formName = " DVForm " />的formName属性对应的是进行验证的ActionForm的name属性?font style="BACKGROUND-COLOR: #ffffff">onsubmit="return validateDVForm(this)"为固定写法,格式为:onsubmit="return validateXXX(this)"QXXX为Form的name属性,其中首字母大写就可以了?br />

实验二: 由ValidatorForm的子cVForm来验?br />
他的配置信息只需要将实验一中底色ؓ黄色高亮部分的DVForm换成VForm可以了Q他们的区别只在于一个是动态的Q一个是非动态的?br />

实验?由DynaValidatorActionForm的子cDVAForm来验?br />
该实验的配置信息只需要将实验一struts-config.xml中底色ؓ黄色高亮部分的DVForm换成DVAForm可以了Q其ơ是修改validation.xml的内?具体如下Q?br />
1 <form-validation>    
2     <formset>
3         <form name="/index">
4             <field property="name" depends="required">
5                 <arg0 name="required" key="lable.name"/>
6             </field>
7         </form>
8     </formset>
9 </form-validation>

区别?font style="BACKGROUND-COLOR: #ffff00"><form name="/index">中的name属性不再对应的是验证Form的name属性,而是其相对的actioncȝpath属?br />
实验四:由ValidatorActionForm的子cVAForm来验?br />
与实验三一P换掉struts-config.xml中底色ؓ黄色高亮部分的DVAForm换成VAForm可以了Qvalidation.xml文g中的内容与实验三保持一_<form name="/index">中的name属性不再对应的是验证Form的name属性,而是其相对的actioncȝpath属性?br />
不过用DynaValidatorActionForm和ValidatorActionForm的时候好象不能用客L验证Q只能用服务器端验证。还得有高手指点Q因此前台JSP面得改成:

1         <html:form action="/index">
2             name : <html:text property="name"/><html:errors property="name"/><br/>
3             <html:submit/>
4         </html:form>

下面来介l一下validation.xml文g中的一些元素信息:

1?lt;global>中定义的<constant>?lt;formset>中定义的<constant>
前者表C在全局范围内定义常量,可以在validation.xml文g中的其他<formset>中访问。访问格式ؓ${constantName}
后者表C局部的帔R定义Q只能在声明他的<formset>中用?br />
2?lt;field>元素中的几个子元素:
<!ELEMENT field (msg|arg|arg0|arg1|arg2|arg3|var)*>
也就是说他的所有子元素都可以是0-n个,q一点和孙卫琴的书有出入Q以此ؓ准?br />
msg元素
<msg name="" key="" bundle="" resource=""/>

nameQ表C验证规则的逻辑名;
keyQ对应资源文件中的keyQ?br />bundleQ指定从哪个资源文g获取key|~省时ؓ默认的资源文Ӟ
resourceQؓtrue是表CZ资源文g中获取key属性对应的信息Qؓfalse时表C直接显Ckey属性的内容Q和资源文g无关。缺省ؓtrue?br />
Strust框架中指定了一些常用规则的对应文本Q验证框枉认是从这些对应的文本中读取信息。但是我们可以通过指定msg元素来从自定义的资源文g或者是key中来获取消息?br />
arg.....元素用来指定复合文本中的参数Q依ơ对应。他们的属性和msg的属性很怼Q用法也是一L?br />
var元素
 1     <formset>
 2         <form name="/index">
 3             <field property="name" depends="required">
 4                 <arg0 name="required" key="${var:required}" resource="false"/>
 5                 <var>
 6                     <var-name>required</var-name>
 7                     <var-value>xx</var-value>
 8                 </var>
 9             </field>
10         </form>
11     </formset>


如果执行了该验证的话Q输出的l果为:xx is required.








kook 2006-09-25 20:50 发表评论
]]>
Struts学习W记http://www.aygfsteel.com/kook/articles/71710.htmlkookkookMon, 25 Sep 2006 04:26:00 GMThttp://www.aygfsteel.com/kook/articles/71710.htmlhttp://www.aygfsteel.com/kook/comments/71710.htmlhttp://www.aygfsteel.com/kook/articles/71710.html#Feedback0http://www.aygfsteel.com/kook/comments/commentRss/71710.htmlhttp://www.aygfsteel.com/kook/services/trackbacks/71710.html  

一?/span> 如何获得 ApplicationResources.properties 中的信息


1
、获得默认的资源文g

1 MessageResources messages =  getResources(request);
2 

3 String title = messages.getMessage("hello.jsp.title" );
4 



2
、获得默认的资源文g

1 MessageResources resources =  (MessageResources) request.
2 

3 getAttribute(Globals.MESSAGES_KEY);
4 



3
、获得指?span lang="EN-US">key的资源文?/font>

MessageResources messages  =  getResources(request, " en " );

 

其实Ҏ一本质上就是调用方法二来获?/span> MessageResources 的实例?span lang="EN-US">

首先获得一个封装了 ApplicationResources.properties 信息

的对?/span> MessageResources 的实?span lang="EN-US">messagesQ然后调?span lang="EN-US">getMessage(key);来获?span lang="EN-US">key的?span lang="EN-US">

二?/span> 如何打包发布一?span lang="EN-US">WEB应用

?span lang="EN-US">DOC下{到应用的根目录执?span lang="EN-US">jar cvf appName.war *.*

三?/span> 如何?span lang="EN-US">formbean下验证表?span lang="EN-US">

 

 1 ActionErrors errors = new  ActionErrors();
 2 

 3     String array[] = new String[2 ];
 4 

 5     array[0= "xx" ;
 6 

 7     array[1= "hh" ;
 8 

 9     if(name==null || name.length()<1 )
10 

11      {
12 

13        errors.add("name",new ActionMessage("kong",false ));
14 

15     //对应的key为hello,且hello为动态复合消息,array数组用来替换复合消息中的参数
16 
17        errors.add("name",new ActionMessage("hello" ,array));
18 

19      }
20 

21 return  errors;
22 

23 

 

?span lang="EN-US">inputJSP中用 <html:errors/> 获取q显C?span lang="EN-US">

 

四?/span> ?span lang="EN-US">action下处理业务逻辑时返回的错误信息

 1 ActionErrors errors =  new ActionErrors();
 2 

 3
 String userName  = (String)((HelloForm) form).getUserName();
 4 

 5
   
 6 

 7
 String badUserName = "Monster ";
 8 

 9
   
10 

11
  if (userName.equalsIgnoreCase(badUserName)) {
12 

13
      errors.add("username"new ActionError("hello.dont.talk.to.monster ", badUserName ));
14 

15
      saveErrors(request, errors);       // l定到request对象?br />16 
17
      return ( new ActionForward(mapping.getInput()));
18 

19
   }
20 


同样在相应的JSP面中用?lt;html:errors/>
获取q显C?br />

 

五?/span> JSP 中如何访?span lang="EN-US">action

1 ?br />

< A href = " <%=request.getContextPath() %>/hello.do " > Link </ A >

 

2 、自动蟩?br />


   
A_JSP
面Q?span lang="EN-US">

< logic:forward name = " gaga " />


B_struts-config.xml
讄Q?br />


< global - forwards  >

      <
forward name = " gaga "  path = " /hello.do " ></ forward
>

</
global - forwards >


六?/font>
配置错误面和异帔R面:《精?span lang="EN-US">Struts?/font> page_75


七?/font>
如何?span lang="EN-US">Web应用中访?span lang="EN-US">Locale对象


1
、什么是LocaleQ?br />
java.util.Locale cȝ实例代表一U特定的语言环境和地?br />


2
如何获得LocaleQ?span lang="EN-US">

̔        构造函?span lang="EN-US">

Locale locale  =   new  Locale( " en " , " US ");
Locale locale 
=   new  Locale( " ch " , " CH " );


̔    
讉Kjava.util.Localecȝ静态常量来获得常用?/span> Locale 实例

Locale locale  =  Locale.CHINA;     (zh_CN)
Locale locale 
=  Locale.CHINESE;   (zh)

̔        通过HttpServletRequest对象来获得客L?span lang="EN-US">Locale

Locale locale  =  request.getLocale();   // 获得优先使用?/span>Locale
System.out.println(locale);

 

// 获得所有LocaleQ从优先U高的依ơ降序排列ƈ打印出来?/span>
Enumeration locales  =  request.getLocales();

while
 (locales.hasMoreElements()) {
      Locale element 
=
 (Locale) locales.nextElement();
      System.out.println(element);
}


̔       
通过HttpSession对象来获?span lang="EN-US">Locale

HttpSession session  =  request.getSession();

Locale locale 
=
 (Locale) session.

getAttribute(Globals.LOCALE_KEY);

System.out.println(locale);

 

获得Locale的方法还有很多,其实?span lang="EN-US">Web应用中,很多获得Locale的方法都是不同程度的或者是直接的或者是间接在调?/span> request.getLocale(); Ҏ。因此有?/span> HttpServletRequest Q我们可以做很多事情?span lang="EN-US">



kook 2006-09-25 12:26 发表评论
]]>
ActionMessagescd其绑定的lghttp://www.aygfsteel.com/kook/articles/71626.htmlkookkookSun, 24 Sep 2006 18:54:00 GMThttp://www.aygfsteel.com/kook/articles/71626.htmlhttp://www.aygfsteel.com/kook/comments/71626.htmlhttp://www.aygfsteel.com/kook/articles/71626.html#Feedback0http://www.aygfsteel.com/kook/comments/commentRss/71626.htmlhttp://www.aygfsteel.com/kook/services/trackbacks/71626.html 首先来了解一下ActionMessagescȝl构Q?br />



在ActionMessages中包含着一个HashMapQ其中的key是addҎ的property参数Q然而他的值对应的是一个ActionMessageItem,ActionMessageItem是该cȝ一个内部类Q当中包含了一个ArrayList?br />由此可见Q一个property中可以包含着多个ActionMessage,q些ActionMessage都将保存在ActionMessageItem的ArrayList中?br />

 1 public void  add(String property, ActionMessage message) {
 2 

 3         ActionMessageItem item =  (ActionMessageItem) messages.get(property);
 4         List list = null
;
 5 

 6         if (item == null ) {
 7             list = new
 ArrayList();
 8             item = new ActionMessageItem(list, iCount++
, property);
 9 

10              messages.put(property, item);
11         } else
 {
12             list =
 item.getList();
13 
        }
14 

15          list.add(message);
16 

17     }



每次d新的ActionMessage中,ActionMessagescM判断HashMap中的get(property)是否存在Q如果存在的话,p得该list = item.getList();q把ActionMessaged到其中。如果不存在Q就会创Z个新的list = new  ArrayList();
再将内容d到当中去。ȝ来说QActionMessages是一个保存信息的容器。通常ActionMessages是不会单独用的Q和他相关的一些Strutslg会对其进行访问和操作Q?br />
<html:errors>标签

<html:errors>标签是一个StrutslgQ他的内部标{对ActionMessagescȝ子类ActionErrorsq行讉K。通过在request和session中找到ActionErrors来获得相关信息。在此之前,先来了解?lt;html:errors>标签的几个重要属性:

name属性:
指定ActionMessages在request和session范围内的属性key.默认gؓGlobals.ERROR_KEY。由此我们可以了解到Struts是如此保存和获取ActionMessages的:

保存Q?br />ActionErrors errors = new ActionErrors();

request.setAttribute(Globals.ERROR_KEY ,errors);或?br />
session.setAttribute(Globals.ERROR_KEY ,errors);

获取Q?br />ActionErrors errors = new ActionErrors();

errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY);或?br />
errors = (ActionErrors)session.getAttribute(Globals.ERROR_KEY);或?br />
该属性通常我们不用讄和更改他Q用默认值就可以啦?br />
property属性:
用来指定消息的属性,如果不设|该属性,那么<html:errors>标签显CActionMessages中的所有属性。如果设|了该属性,则只昄HashMap中Key为property属性值的ArrayList集合。通常Q我们在调用ActionMessages的addҎӞ会指定addҎ的property参数Q也是W一个参敎ͼ相关信息添加到指定的property对应的ArrayList中。那么我们要昄相关信息Ӟ可以指定输?lt;html:errors>标签的property属性对应的ArrayListQ这两个property是相互对应的?br />
bundle属性:
指定资源文g的key属性。缺省的情况下调用的是默认的资源文gApplication.properties?br />如在struts-config.xml中声明的资源文g信息如下Q?/font>

  < message - resources parameter = " com.kook.struts.ApplicationResources "   />
  
< message - resources key = " ch "  parameter = " com.kook.struts.ApplicationResources_ch "   />
  
< message - resources key = " en "  parameter = " com.kook.struts.ApplicationResources_en "   />

对应的addҎ如下Q?/font>

1 ActionErrors errors = new  ActionErrors();
2 if(name==null || name.length()<1
)
3 
{
4       errors.add("name",new ActionMessage("kong"
));
5 
 }
6  return errors;

new  ActionMessage( " kong " )对应在key="en"的资源文件中为:

kong=bu neng wei kong

JSP中的<html:errors>标签Q?/font>

1 <html:errors property="name" bundle="en"/>

q时候将会输出key="en"的资源文件中?kong"对应的信息:bu neng wei kong

<html:messages>标签

<html:messages>标签是用来在JSP面上输Z条消息的。通常我们在做d数据的时候,如果d成功Q通常会在前台面反馈l用户一条“添加成功”的信息Q这时候我们就可以用到q个标签?br />
name属性:

是指ActionMessages对象保存在request或session中的属性keyQ即request.setAttribute("heihei", messages);中的W一个参数?br />
message属性:如果为trueQ表C是从request或session中取得key为Globals.MESSAGE_KEY的ActionMessages对象Q此时该标签讄的name属性的无效的。如果ؓfalseQ表CZ该标{name属性来获得request或session的key倹{缺省值就为false?br />
id属性:q个属性就不说了,索出ActionMessages集合中单个对象的标识Q他?lt;logic:iterate>的id是同一个意思?br />
实验:

在action中的executeҎ中添加如下代码:

1 ActionMessages messages = new ActionMessages();
2         
3 messages.add(""new ActionMessage("haha",false));
4         
5 this.saveMessages(request, messages);        
6 
7 return new ActionForward("/form/hello.jsp");

表示往ActionMessages对象中添加一条信?span style="COLOR: #0000ff">new ActionMessage("haha",false)Qƈ保存在request当中this.saveMessages(request, messages);  那么在这个方法中Q他是如何保存ActionMessage对象的呢Q下面是 saveMessages Ҏ的源代码Q?/span>

 1 protected void saveMessages(
 2         HttpServletRequest request,
 3         ActionMessages messages) {
 4 
 5         // Remove any messages attribute if none are required
 6         if ((messages == null|| messages.isEmpty()) {
 7             request.removeAttribute(Globals.MESSAGE_KEY);
 8             return;
 9         }
10 
11         // Save the messages we need
12         request.setAttribute(Globals.MESSAGE_KEY, messages);
13     }

观察q段代码不难发现Q他是将ActionMessages存放在key为Globals.MESSAGE_KEY当中的,因此我们在调用ActionMessages的addҎӞ他的property参数QaddҎ的第一个参敎ͼ没有必要让我们自己L动指定了Q因ZZ指定什么参敎ͼ只要调用了saveMessagesҎQ这是前提)Q他只会信息保存在固定的常量key中?br />q时前台的hello.jsp面的显CZ码ؓQ?/p>

1 <html:messages id="a" message="true">
2     <bean:write name="a"/>
3 </html:messages>

上面代码讄了message属性,表示从Globals.MESSAGE_KEY中获取信息,前面也有提到Q此时指定name属性是无效的?br />
那如果我惛_昄我自己指定的信息怎么办呢Q?br />
我们可以不用saveMessagesҎ而用最原始的办法,通常最原始的办法也是最有效?Struts其实是封装了许多最原始的实现。我们先action中的代码改ؓQ?/p>

ActionMessages messages  =   new  ActionMessages();
        
messages.add(
"" new  ActionMessage( " haha " , false ));
        
request.setAttribute(
" show " , messages);

return   new  ActionForward( " /form/hello.jsp " );

然后在JSP面中指定name属性,而将message设ؓfalse可以了Q?/p>

1 <html:messages id="a" name="show">
2     <bean:write name="a"/>
3 </html:messages>

q里是直接省略了message属性,因ؓ他的~省值就是false。这样就可以辑ֈ输出自己指定属性的信息啦!




 



kook 2006-09-25 02:54 发表评论
]]>
资源文g中复合消息的实现http://www.aygfsteel.com/kook/articles/71624.htmlkookkookSun, 24 Sep 2006 16:48:00 GMThttp://www.aygfsteel.com/kook/articles/71624.htmlhttp://www.aygfsteel.com/kook/comments/71624.htmlhttp://www.aygfsteel.com/kook/articles/71624.html#Feedback0http://www.aygfsteel.com/kook/comments/commentRss/71624.htmlhttp://www.aygfsteel.com/kook/services/trackbacks/71624.html在Struts框架中,往往需要对资源文gq行配置Q从而实现国际化的目的?br />
资源文g中允怋用静态和动态文本。通过动态文本来动态的讑֮其显C的内容Q从而能更好的减代码的冗余Q然而动态文本中的参数指定,是通过什么来实现的呢Q?br />
下面是ApplicationResources.properties资源文g中的内容Q?br />
1 # Resources for parameter 'com.kook.struts.ApplicationResources'
2 # Project P/ Demo_242103
3 

4 
5 
6 hello={0} is the brother of {1 }
7 hello.brother=
zhangsan
8 hello.person=lisi

通常我们可以在验证框架的配置文g中来配置其动态参数的|如:

1 <field property="name" depends="required">
2                 <arg0 name="required" key="hello.brother"/>
3  </field>

但是具体的实现可以通过java.text.MessageFormatcL实现

1       MessageResources messages =  getResources(request);
2         String title = messages.getMessage("hello"
);
3         String[] arr = new String[2
];
4         arr[0= messages.getMessage("hello.brother"
);
5         arr[1= messages.getMessage("hello.person"
);
6         String newMessage =
 MessageFormat.format(title, arr);
7         System.out.println(newMessage);

最后输出:zhangsan is the brother of lisi

 

 



kook 2006-09-25 00:48 发表评论
]]>
logic:present ?logic:empty标签http://www.aygfsteel.com/kook/articles/71605.htmlkookkookSun, 24 Sep 2006 14:35:00 GMThttp://www.aygfsteel.com/kook/articles/71605.htmlhttp://www.aygfsteel.com/kook/comments/71605.htmlhttp://www.aygfsteel.com/kook/articles/71605.html#Feedback0http://www.aygfsteel.com/kook/comments/commentRss/71605.htmlhttp://www.aygfsteel.com/kook/services/trackbacks/71605.htmllogic:present ?logic:empty他们的用法大致相同,唯一的不同点是:两者在对空字符串的处理上存在着不同?br />

下面为index.jsp中的代码Q?br />
 1 <logic:notPresent name="users">
 2  notpresent
 3 </logic:notPresent>
 4 <logic:notEmpty name="users">
 5  notempty
 6 </logic:notEmpty>
 7 <logic:empty name="users">
 8  empty
 9 </logic:empty>
10 <logic:present name="users">
11  present
12 </logic:present>


当第一ơ访问该JSP的时候,׃users没有定义Qƈ且也不在page,request,session,applicationM一个作用域中,因此输出的结果ؓnotpresent,empty?br />
下面我们增加一个actionQ让他在index.jsp之前执行Q然后再跌{到index.jsp中,同时在该action的executeҎ中增加如下代码:
 
1String userName = "";
2request.setAttribute("users", userName);
3return new ActionForward("/index.jsp");
4
q里userName保存在request中,key为usersQ再请求{发至index.jsp中,但是userName的gؓ一个空字符Ԍ转发q后Q输出的gؓQempty,present

q里我们再做一ơ改动,action的executeҎ中的代码改ؓQ?br />
1String userName = null;
2request.setAttribute("users", userName);
3return new ActionForward("/hello.jsp");
4
不同的是userName 不再为空字符串了Q而是null|当{发至index.jsp后,输出的gؓQnotpresent,empty ?br />
Ҏq几ơ改动,我们可以得出l论Q?br />
对于没有在page,request,session,application中定义或者是没有分配内存I间(null?的变量,q两个标记处理的Ҏ是一致的Q都会认为此变量不存?notpresent)或者ؓI?empty)。而对于空字符?"|他们的处理就不一样了Qlogic:present 标记认ؓI字W串仍然是存在的Q也是_只要是引用了一块内存空间的变量Qlogic:present ׃q回present Q而logic:empty则认为空字符串仍然ؓI,由此得出Q在logic:empty看来Q变量不仅仅要引用一块内存空_而且该地址I间的g能ؓI字W串Q否则都认ؓ该变量ؓI,都会q回empty


kook 2006-09-24 22:35 发表评论
]]>
վ֩ģ壺 ƽ| | ɽ| | | | | ƽɽ| | | | | | | ʯ̨| | Դ| ƽ| | | ®| | | | | | ֶ| | | ƽ| г| | Դ| | | | | ˷| | | IJ|