STRUTS 标签用法

把list填充到select 中: 

 <%
    ArrayList list = new ArrayList();
    list.add(new org.apache.struts.util.LabelValueBean("a1","value1"));
    list.add(new org.apache.struts.util.LabelValueBean("a2","value2"));
    list.add(new org.apache.struts.util.LabelValueBean("a3","value3"));
    pageContext.setAttribute("valueList",list); 
   
     %>
     <html:form action="/test.do">
      <html:select property="testString">
      <html:options collection="valueList" property="value" labelProperty="label"/>
      </html:select>
     </html:form> 

 

一:显示资源文件中的某个KEY对于的VALUE:
 <message-resources parameter="com.struts.ApplicationResources" key="beanmessage" />

ApplicationResources.properties文件内容:
beanMessage1=THis is bean message No1
beanMessage2=THis is bean message No2
beanMessage3=THis is bean message with arg,{0}.

Method 1 :
<bean:message bundle="beanmessage" key="beanMessage1"/>

Method 2:
    <%
    String test="beanMessage2";
    pageContext.setAttribute("messageKey",test);
     %>
     <bean:message bundle="beanmessage" name="messageKey"/>

Method 3:
<%
TestPageBean bean1= new TestPageBean("beanMessage1","empty");
pageContext.setAttribute("testbean",bean1);
 %>
 <bean:message bundle="beanmessage" name="testbean" property="name"/>

如果带参数,改为以下:
 <bean:message bundle="beanmessage" key="beanMessage3" arg0="HELLOWORLD"/>
运行结果:THis is bean message with arg,HELLOWORLD.

 

一:显示资源文件中的某个KEY对于的VALUE:
 <message-resources parameter="com.struts.ApplicationResources" key="beanmessage" />

ApplicationResources.properties文件内容:
beanMessage1=THis is bean message No1
beanMessage2=THis is bean message No2
beanMessage3=THis is bean message with arg,{0}.

Method 1 :
<bean:message bundle="beanmessage" key="beanMessage1"/>

Method 2:
    <%
    String test="beanMessage2";
    pageContext.setAttribute("messageKey",test);
     %>
     <bean:message bundle="beanmessage" name="messageKey"/>

Method 3:
<%
TestPageBean bean1= new TestPageBean("beanMessage1","empty");
pageContext.setAttribute("testbean",bean1);
 %>
 <bean:message bundle="beanmessage" name="testbean" property="name"/>

如果带参数,改为以下:
 <bean:message bundle="beanmessage" key="beanMessage3" arg0="HELLOWORLD"/>
运行结果:THis is bean message with arg,HELLOWORLD.


二:
变量定义:
<bean:define id="testString" value="This is a test string"/>
<bean:write name="testString"/>

三:struts-logic标签:

1:判断指定变量是否相等
<%
pageContext.setAttribute("test",new Integer(1000));
 %>
 <logic:equal name ="test" value="1000">
 变量test等于1000
 </logic:equal>

2.header属性:
<logic:equal header="host" value="localhost:8080">
主机地址为localhost:8080
</logic:equal>

3.
  <html:link page="/beanTag.jsp?testInt=1234">添加参数</html:link>
  <logic:greaterEqual parameter="testInt" value="1000"> more than 1000</logic:greaterEqual>
结果:more than 1000

4.
<%
javax.servlet.http.Cookie newcookie= new javax.servlet.http.Cookie("cookiename","cookieevalue");
newcookie.setComment("new Cookie");
newcookie.setMaxAge(3600);
response.addCookie(newcookie);
 %>
 <logic:equal cookie="cookiename" value="cookieevalue">cookiname,cookievalue</logic:equal>
 
5.
<logic:lessThan name="" value=""/>
<logic:lessEqual name="" value=""/>
<logic:greaterThan name="" value=""/>


6.<logic:iterate>

<%
String[] testArray1={"str0","str1","str2","str3","str4"};
pageContext.setAttribute("test1",testArray1);
 %>
 <logic:iterate id="array1" name="test1" length="4" offset="1">
 <bean:write name="array1"/>
 </logic:iterate>

对HashMap进行遍历
<%
HashMap countries = new HashMap();
countries.put("1","china");
countries.put("2","unite");
pageContext.setAttribute("country",countries);
 %>
 <logic:iterate id="contry" name="country">
 <bean:write name="contry" property="key"/>
  <bean:write name="contry" property="value"/>
 </logic:iterate>

对list进行遍历:
<%
ArrayList countries = new ArrayList();
countries.add("china");
countries.add("unite");
pageContext.setAttribute("country",countries);
 %>
 <logic:iterate id="contry" name="country">
 <bean:write name="contry"/>
  </logic:iterate>

嵌套遍历:
<%
String[] color= {"red","green","blue"};
String[] countries={"china","unit","franch"};
String[] person = {"乔丹","Rose","Kld"};
ArrayList l = new ArrayList();
l.add(color);
l.add(countries);
l.add(person);
pageContext.setAttribute("ll",l);
 %>
 <logic:iterate id="first" name="ll">
 
  <logic:iterate id="second" name="first">
   <bean:write name="second"/>
  </logic:iterate>
  <br>
  </logic:iterate>

运行结果:
red green blue
china unit franch
乔丹 Rose Kld


7.Match标记:
<logic:match>
<logic:notMatch>

<%
 pageContext.setAttribute("test","Hello,World");
 %>
 <logic:match name="test" value="Hello">
  <bean:write name="test"/>
  </logic:match>


<%
 pageContext.setAttribute("test","Hello,World");
 %>
 <logic:notMatch name="test" value="kk">
  <bean:write name="test"/>
  </logic:notMatch>

8.<logic:present>
<%
 pageContext.setAttribute("ExistingString","testing");
 
 %>
 <logic:present name="ExistingString">
 <bean:write name="ExistingString"/>
 </logic:present>

<logic:messagesPresent>

9.
<logic:empty>
<logic:notEmpty>

 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值