Struts标签库

1、struts-html

2、struts-bean

3、struts-logic

一:<html>
    <html:form action="/reg" method="post">
          <html:text property="account"/>
          <html:password property="password"/>
          <html:textarea property="UserInfo" rows="6" cols="10" value=""></html:textarea>
          <html:hidden property="hiddeninfo"></html:hidden>
          <!--RegForm.java==> Private String sex="boy"-->
          <html:radio property="sex" value="boy"></html:radio>男
          <html:radio property="sex" value="girl"></html:radio>女
          <!---->
          <html:select property="home" value="hubei" muliple="true" size="5">
              <html:option value="hunan">湖南</html:option>
              <html:option value="hubei">湖北</html:option>
              <html:option value="zhejiang">浙江</html:option>
          <html:select>

          <!--RegForm.java==>private String[] fav={"sing"}-->
           <html:multibox property="fav" values="sing" ></html:multibox>唱歌
           <html:multibox property="fav" values="drink" ></html:multibox>喝酒
           <html:multibox property="fav" values="dance" ></html:multibox>跳舞
           <html:multibox property="fav" values="eat" ></html:multibox>吃肉

          <!--RegForm.java==>private boolean inteam
             reset(){ this.inteam=false;}-->
           <html:checkbox property="inteam"></html:checkbox>
        </html:form>
    <!--Result.jsp参数的值全从RegForm.java中读取-->
         <%
             String[] fav=regform.getFav();
             for(int i=0;i<fav.length;i++)
             {
               out.println(fav[i]);
              }
          %>


二:<html:link>
<html:link page="/jsp2.jsp">链接1</html:link>
<html:link href="jsp2.jsp">链接2</html:link>
<html:link forward="JSP2"></html:link>
struts-config.xml
<global-forwards>
   <forward name="JSP2" path="/jsp2.jsp"></forward>
</global-forwards>

<html:link action="/XXXaciotn.do">诸如退出登陆之类</html:link>


<%
  request.setAttribute("UserName","jembai");
  session.setAttribute("UserName","jembai");
  application.setAttribute("UserName","jembai");
%>
<!--"page"==>"request"==>"session"==>"application"-->
<html:link page="/jsp2.jsp" paramId="param" paramName="UserName"></html:link>

  <!--传某一个对象的一个属性值-->
<%   Student stu=new Student();
   stu.setStuid("0002");
   session.setAttribute("stu",stu);
%>
<html:link page="/jsp2.jsp" paramId="param" paramName="stu" paramProperty="stuid">传某一个对象的一个属性值</html:link>
<%
  <!--多参数传参-->
  HashMap mp=new HashMap();
    mp.put("param1","001");
    mp.put("param2","002");
    mp.put("param3","003");
 session.setAttribute("hashmap",mp);
%>
<html:link page="/jsp2.jsp" name="hashmp">hash多参数传值</html:link>

三:<bean>
    <bean:parameter>==request.getParameter("");
    <%
      String str=request.getParameter("param");
      out.print(str);
     %>
     转化为bean标签为:
    <bean:parameter id="str" name="param"/>
    <bean:write name="str" filter="false"/>
    <beam:write name="stu" property="stuid"/>

    读Cookie的标签:
    写Cookie:
    <%response.addCookie(new Cookie("UserName","jembai"))%>
    读Cookie:
    <bean:cookie name="UserName",id="myCookie"/><bean:write name="myCookie" property="value"/> 

四:<Logic>

    <logic:equal name="str" value="001">
      OK
    </logic:equal>
   
    <logic:notequal>
    </logic:notequal>
     <logic:greaterEqual>
   
    <logic:lessEqual>
   
    <logic:lessThan>

    <logic:present name="stu"></logic:present>

    <logic:notPresent></logic:notPresent>====>"if(XXX!=NULL)"
   
    <logic:greaterThan>

    <!--遍历数组-->
    <%
     ArrayList Books=new ArrayList();
     books.add("三国演义");
     books.add("水浒传");
     books.add("红楼梦");
     session.setAttribute("books",books);
    %>
    <logic:iterate id="book" name="books">
     <bean:write name="book"/>
    </logic:iterate>   

    <%
    ArrayList stus=new ArrayList();

    Students stu1=new Students(); stu1.setStuid("0001"); stus.add(stu1);
   
    Students stu2=new Students(); stu2.setStuid("0001"); stus.add(stu2);
    
    Students stu3=new Students(); stu3.setStuid("0001"); stus.add(stu3); 

    session.setAttribute("stus",stus);
    %>

   <logic:iterate id="stu" name="stus" >
      <bean:write name="stu" property="stuid"/>
   </logic:iterate>

   <%
    ArrayList phones=new ArrayList();
    phones.add("234534556");
    phones.add("456456243");
    Students stu4=new Students();
    stu4.setPhones(phones);
    session.setAttribute("stu4",stu4);

   %>
   <logic:iterate id="phone" name="stu4" property="phones">
      <bean:write name="phone"/>
   </logic:iterate>
   <!--遍历HashMap-->
   <%
      HashMap mp=new HashMap();
      mp.put("param1","001");
      mp.put("param2","002");
      mp.put("param3","003");
      session.setAttribute("hashmap",mp);
    %>
    <logic:iterate id="element" name="hashmap">
      <bean:write name="element" property="key"/>
      <bean:write name="element" property="value"/>
    </logic:iterate>

 

 

 

 

posted on 2009-07-30 16:20  草原和大树  阅读(428)  评论(0编辑  收藏  举报