隨筆-54  評(píng)論-0  文章-2  trackbacks-0

          昨天講的Struts的流程,今天講的是StrutsActionFormBeanStruts的標(biāo)簽

          今天學(xué)好后為struts回顯打下堅(jiān)實(shí)基礎(chǔ),struts基本也就這些內(nèi)容了!

          1.ActionFormBean的基本步驟

           總結(jié):

              <action path="/login" name="loginForm" attribute =”ss” type="com.itcast.struts.action.LoginAction" scope="request">。》

          scope的默認(rèn)值是session

          action標(biāo)簽中attribute屬性的值 作用是實(shí)現(xiàn)重用

          如不設(shè)置 默認(rèn)值action標(biāo)簽中name屬性的值 mapping.getAttribute() loginForm

          如設(shè)置attribute屬性的值 輸出的值為設(shè)置的值mapping.getAttribute() ss

          看底層代碼:

           底層代碼 

                instance 表示ActionForm的實(shí)例

                if ("request".equals(mapping.getScope())) {

                      request.setAttribute(mapping.getAttribute(), instance);

                      request.setAttribute(mapping.getAttribute(), instance);

                  } else {

                      HttpSession session = request.getSession();

                      session.setAttribute(mapping.getAttribute(), instance);

                  }

           如不設(shè)置attribute屬性默認(rèn)值action標(biāo)簽中name屬性的值的底層代碼

           public String getAttribute() {

                  if (this.attribute == null) {

                      return (this.name);

                  } else {

                      return (this.attribute);

                  }

              }

           StrutsActionForm對(duì)象默認(rèn)放在session作用域中只要是轉(zhuǎn)發(fā)通用

          2.處理ActionFormBean的基本步驟

           ActionForm的執(zhí)行流程(ActionServlet自動(dòng)調(diào)用)

                 1檢查并確認(rèn)在Action中已經(jīng)配置了對(duì)表單Bean的映射。

                    * 查找<action path="/login" name="loginForm" 當(dāng)中是否含有name屬性必須存在

                    * 如是<a href="/login.do">test</a> 這是就不需要action中的name屬性

                 2)根據(jù)表單Beanname屬性,查找表單Bean的配置信息

                    檢查頁(yè)面的標(biāo)簽的name屬性的值是否和ActionForm中的屬性對(duì)象

                    <input type="text" name="username" /> 是否存在username這個(gè)屬性

                 3)檢查該表單Bean的使用范圍,查找在該范圍內(nèi),是否已存在該Bean的實(shí)例。如果已經(jīng)存在,那么就重用該實(shí)例。否則,就重新創(chuàng)建一個(gè)。

                    name="loginForm" scope="request"   attribute="ss"

                 //增加新的

                     if ("request".equals(mapping.getScope())) {

                      request.setAttribute(mapping.getAttribute(), instance);

                  } else {

                      HttpSession session = request.getSession();

                      session.setAttribute(mapping.getAttribute(), instance);

                  }

                 //查找原有的

                  if ("request".equals(scope)) {

                      instance = (ActionForm) request.getAttribute(attribute);

                  } else {

                      session = request.getSession();

                      instance = (ActionForm) session.getAttribute(attribute);

                  }

                 4調(diào)用該Bean實(shí)例的reset()方法重置其狀態(tài)。

                    //ActionForm中的屬性,恢復(fù)到初始時(shí)null,獲取默認(rèn)的初始值

                 5)調(diào)用該Bean實(shí)例相應(yīng)的setter方法,使用請(qǐng)求表單中的數(shù)據(jù)填充Bean的屬性。

                 6)如果起用了validate機(jī)制,則調(diào)用表單Beanvalidate()方法。如果validate()方法返回任何錯(cuò)誤,則跳過(guò)步驟7)轉(zhuǎn)到預(yù)定的出錯(cuò)處理頁(yè)面。

                 7)將該表單Bean實(shí)例作為參數(shù),傳給處理器對(duì)象的execute()方法并執(zhí)行。

                  Person person=new Person();

                  person.serUsernmae("zhang");

                  person.setPsw("tonggang")

                  request.setAttribute("person",person)

                  Person person=(Person)request.getAttribute("person");

                  //不存在的情況

                  if(person==null){

                      Person p=new Person();

                      request.setAttribute("person",p)

                  }else{

                  //存在的情況下 reset

                  person.setUsernmae(null)l

                  pserson.setPsw(null);

                  

                  System.out.println(persoon.getUsername()); //zhang

                  }

                  

          /////////////////////////////////////////////////////////////////////////////////////////////////////// 

                 <a href="${pageContext.request.contextPath}/a.do">test</a>

                 <!-- 中間不做什么工作,直接使用 forward 轉(zhuǎn)到需要頁(yè)面-->

               <action path="/a" forward="/success.jsp"></action>

                  優(yōu)點(diǎn):

                 <a href="${pageContext.request.contextPath}/success.jsp">test</a>

          //////////////////////////////////////////////////////////////////////////////////////////////////////  

          3.

          下面是非常重要的DispatchAction,在項(xiàng)目中非常有用

          dispatcheAction的使用規(guī)則 

             * 定義的類要繼承 public class EmpAction extends DispatchAction

             * 該類中的方法定義規(guī)則  

                 * 方法名稱自定義(要和jsp頁(yè)面中的參數(shù)的值一致)

                    * 方法的參數(shù)個(gè)數(shù),參數(shù)類型,參數(shù)順序和方法的返回類型要與action中的execute()方法一致

                   

             * jsp頁(yè)面中的使用

                   路徑如下

                    method=save 參數(shù)名稱   method自定義 參數(shù)名稱要和<action> parameter屬性的值相同

                         參數(shù)值     save要和EmpAction中的方法名稱相同

                  action="${pageContext.request.contextPath}/empAction.do?method=save"

             * Struts-config.xml文件中的配置如下

                 <!--

                              method=save

                              parameter="method"

                              parameter的值是在jsp頁(yè)面中參數(shù)的名稱,

                                        struts在解析的時(shí)候,根據(jù)parameter參數(shù)的值獲取到method,在獲取到method參數(shù)的值save

                                               * String methodName=mapping.getParameter(); //method;

                                                  * String paramValue=request.getParameter(methodName); //save

                                                  * //調(diào)用action中的save方法

                             

                               -->

                              <action path="/empAction" name="empForm" scope="request"

                                 type="com.itcast.struts.action.EmpAction" parameter="method">

                              </action>

          3.下午講的Struts標(biāo)簽

          Struts標(biāo)簽離開(kāi)Struts環(huán)境就不能使用了

          使用Struts標(biāo)簽

          1.導(dǎo)入jar

          2.頁(yè)面引入

          <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

          <html:html lang="true">

           <body>

              <html:form action="" method="post" focus="name">

                <table border="0">

                  <tr>

                    <td>用戶名:</td>

                    <td><html:text property="name" /></td>

                  </tr>

                  <tr>

                    <td>密碼:</td>

                    <td><html:password property="password" /></td>

                  </tr>

                  <tr>

                    <td colspan="2" align="center"><html:submit /></td>

                  </tr>

                </table>

              </html:form>

           </body>

          </html:html >

          3.常見(jiàn)錯(cuò)誤及處理:

          FormEmpForm為例,ActionEmpAction為例

          錯(cuò)誤:

          javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action: "/"

             <html:form action="empAction_save" method="post"> Actionstruts-config.xml文件中必須存在對(duì)應(yīng)的action

             <action path="/empAction_save">

             </action>

          javax.servlet.ServletException: javax.servlet.jsp.JspException:

                Form bean not specified on mapping for action: "empAction_save.do"

           原因缺少name="empForm"

           <action path="/empAction_save" name="empForm" scope="request">

           </action>

           --異常

           javax.servlet.ServletException: javax.servlet.jsp.JspException:

                 No getter method for property: "username" of bean: "com.itcast.struts.form.EmpForm"

                                                標(biāo)簽:

             使用標(biāo)簽的源代碼 , struts的解析的過(guò)程中,已經(jīng)到strutc-config.xml文件中找到對(duì)應(yīng)得信息

             該標(biāo)簽中action屬性的值是必須的   focus="psw" 當(dāng)頁(yè)面運(yùn)行的時(shí)候,光標(biāo)自動(dòng)停留在那個(gè)組件上

             <html:form action="empAction_save.do" method="post" focus="psw">

             標(biāo)簽轉(zhuǎn)化后的代碼

           <form name="empForm" method="post" action="/itcast1130strutstaglib/empAction_save.do"> 

             對(duì)應(yīng)的配置文件:

               <action path="/empAction_save" name="empForm" scope="request">

               </action>

            總結(jié):                         action                                      method         name

                    <html:form>標(biāo)簽        empAction_save.do                             post          無(wú)

                    <form>標(biāo)簽              /itcast1130strutstaglib/empAction_save.do     post          empForm(配置文件中name屬性的值)

                   

           ///////////////////////////////////////////////////////////////////////////////////////////////

           使用標(biāo)簽的源代碼 :

                 <html:text property="username" />

           標(biāo)簽轉(zhuǎn)化后的代碼:

                  <input type="text" name="username" value=""> 

                  //////////////////////////// ActionForm給屬性賦初值

                  private String username="tonggang";

                  <input type="text" name="username" value="tonggang"></td>

                   

                                      property                   name

                <html:text>標(biāo)簽         username

                <input>標(biāo)簽                                            username

           /////////////////////////////////////////////////////////////////////////////////////////////// 

           使用標(biāo)簽的源代碼 :

             <html:password property="psw" />

           標(biāo)簽轉(zhuǎn)化后的代碼:

           <input type="password" name="psw" value="" redisplay="false"> 

           redisplay="false" 不執(zhí)行ActionForm getPsw()方法

           redisplay="true"   執(zhí)行ActionForm  getPsw()方法

           ///////////////////////////////////////////////////////////////////////////////////////////////

             使用標(biāo)簽的源代碼 :

           <html:textarea property="des" cols="10" rows="5"/>

             標(biāo)簽轉(zhuǎn)化后的代碼:

           <textarea name="des" cols="10" rows="5"></textarea>

           /////////////////////////////////////////////////////////////////////////////////////////////

               使用標(biāo)簽的源代碼 : html:radio 使用該標(biāo)簽時(shí) value的屬性必須賦值

              <html:radio property="sex" value=""></html:radio>

                 <html:radio property="sex" value=""></html:radio>

                    標(biāo)簽轉(zhuǎn)化后的代碼:          

               <input type="radio" name="sex" value="">

               <input type="radio" name="sex" value="">

            //////////////////////////////////////////////////////////////////////////////////////////////////

                使用標(biāo)簽的源代碼

                <html:checkbox property="love" value="美容"></html:checkbox>美容

                  <html:checkbox property="love" value="籃球"></html:checkbox>籃球

                  標(biāo)簽轉(zhuǎn)化后的代碼:

               <input type="checkbox" name="love" value="美容">美容

                  <input type="checkbox" name="love" value="籃球">籃球            

            //////////////////////////////////////////////////////////////////////////////////////////////////

                         

                    使用標(biāo)簽的源代碼

                          <html:select property="edu">

                             <html:option value="博士">博士</html:option>

                             <html:option value="碩士">碩士</html:option>

                             <html:option value="本科">本科</html:option>

                             <html:option value="小學(xué)">小學(xué)</html:option>

                           </html:select>

                     標(biāo)簽轉(zhuǎn)化后的代碼:                

                  <select name="edu">

                             <option value="博士">博士</option>

                             <option value="碩士">碩士</option>

                             <option value="本科">本科</option>

                             <option value="小學(xué)">小學(xué)</option>

                  </select>        

            //////////////////////////////////////////////////////////////////////////////////////////////////

             使用標(biāo)簽的源代碼           

                      <td> <html:submit>保存</html:submit> <html:submit value="保存"></html:submit></td>

                        <td> <html:reset value="重置"></html:reset></td>

             標(biāo)簽轉(zhuǎn)化后的代碼:       

                    <td> <input type="submit" value="保存"> <input type="submit" value="保存"></td>

                        <td> <input type="reset" value="重置"></td>       

                           

                        

          Link標(biāo)簽

          <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>

          <%@ page import="com.itcast.bean.Person "%>

          <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

          <!--

             html:link標(biāo)簽的使用

          轉(zhuǎn)化后的<a href="/itcast1130strutstaglib/welcome.do">action</a>

          -->

          <html:link action="welcome.do">action</html:link><br>

          <!-- <a href="welcome.do">action</a> -->

          <html:link href="welcome.do">href</html:link><br>

          <!-- forward屬性的值是struts-config.xml文件中的全局forward   <forward name="welcomeforward" path="/welcome.jsp"></forward>-->

          <html:link forward="welcomeforward">forward</html:link><br>

          <!-- <a href="/itcast1130strutstaglib/welcome.jsp">page</a> -->

          <html:link page="/welcome.jsp">page</html:link><br>

          <%

             String user_name="zhang";

             pageContext.setAttribute("username",user_name);

          %><br>

          <!-- <a href="/itcast1130strutstaglib/welcome.do?username124=zhang">paramaction</a><br> -->

          <!--

              paramId 表示參數(shù)的名稱

              paramName 表示參數(shù)的值 值用jstl表示${username} 但在Struts中直接書(shū)寫就可以了

              paramName="username" 就是 pageContext.setAttribute("username",user_name);username(key)

           -->

          <html:link action="welcome.do" paramId="username124" paramName="username">paramaction</html:link><br>

          <!--<a href="/itcast1130strutstaglib/welcome.jsp?username124=zhang">paramaforward</a><br>-->

          <html:link forward="welcomeforward" paramId="username124" paramName="username">paramaforward</html:link><br>

          <!-- <a href="welcome.do?username124=zhang">parama=href</a><br> -->

          <html:link href="welcome.do" paramId="username124" paramName="username" >parama=href</html:link><br>

          <br>

          <br>

          <br>

          <br>

          <%

           Person p=new Person();

           p.setName("xupeicheng");

           pageContext.setAttribute("person",p);

          %>

          <!-- <a href="/itcast1130strutstaglib/welcome.do?name1=xupeicheng">paramaction</a><br> -->

          <!--

              paramId="name1" 表示參數(shù)的名稱

              paramName="person"   表示一個(gè)javaBean

              paramProperty="name" 表示javaBean中的一個(gè)屬性

                   paramName指定的javaBean中獲取paramProperty指定的屬性的值

           -->

          <html:link action="welcome.do" paramId="name1" paramName="person" paramProperty="name" >paramaction</html:link><br>

          <!-- <a href="welcome.do?name1=xupeicheng">paramahref</a><br> -->

          <html:link href="welcome.do" paramId="name1" paramName="person" paramProperty="name" >paramahref</html:link><br>

          <!--<a href="/itcast1130strutstaglib/welcome.jsp?name1=xupeicheng">paramaforward</a><br> -->

          <html:link forward="welcomeforward" paramId="name1" paramName="person" paramProperty="name" >paramaforward</html:link><br>

          5.html:rewrite標(biāo)簽的使用,用于生成url路徑,但并不生成<a>

          昨天講的Struts的流程,今天講的是StrutsActionFormBeanStruts的標(biāo)簽

           

          今天學(xué)好后為struts回顯打下堅(jiān)實(shí)基礎(chǔ),struts基本也就這些內(nèi)容了!

          1.ActionFormBean的基本步驟

           總結(jié):

              <action path="/login" name="loginForm" attribute =”ss” type="com.itcast.struts.action.LoginAction" scope="request">。》

          scope的默認(rèn)值是session

          action標(biāo)簽中attribute屬性的值 作用是實(shí)現(xiàn)重用

          如不設(shè)置 默認(rèn)值action標(biāo)簽中name屬性的值 mapping.getAttribute() loginForm

          如設(shè)置attribute屬性的值 輸出的值為設(shè)置的值mapping.getAttribute() ss

          看底層代碼:

           底層代碼 

                instance 表示ActionForm的實(shí)例

                if ("request".equals(mapping.getScope())) {

                      request.setAttribute(mapping.getAttribute(), instance);

                      request.setAttribute(mapping.getAttribute(), instance);

                  } else {

                      HttpSession session = request.getSession();

                      session.setAttribute(mapping.getAttribute(), instance);

                  }

           如不設(shè)置attribute屬性默認(rèn)值action標(biāo)簽中name屬性的值的底層代碼

           public String getAttribute() {

                  if (this.attribute == null) {

                      return (this.name);

                  } else {

                      return (this.attribute);

                  }

              }

           StrutsActionForm對(duì)象默認(rèn)放在session作用域中只要是轉(zhuǎn)發(fā)通用

          2.處理ActionFormBean的基本步驟

           ActionForm的執(zhí)行流程(ActionServlet自動(dòng)調(diào)用)

                 1檢查并確認(rèn)在Action中已經(jīng)配置了對(duì)表單Bean的映射。

                    * 查找<action path="/login" name="loginForm" 當(dāng)中是否含有name屬性必須存在

                    * 如是<a href="/login.do">test</a> 這是就不需要action中的name屬性

                 2)根據(jù)表單Beanname屬性,查找表單Bean的配置信息

                    檢查頁(yè)面的標(biāo)簽的name屬性的值是否和ActionForm中的屬性對(duì)象

                    <input type="text" name="username" /> 是否存在username這個(gè)屬性

                 3)檢查該表單Bean的使用范圍,查找在該范圍內(nèi),是否已存在該Bean的實(shí)例。如果已經(jīng)存在,那么就重用該實(shí)例。否則,就重新創(chuàng)建一個(gè)。

                    name="loginForm" scope="request"   attribute="ss"

                 //增加新的

                     if ("request".equals(mapping.getScope())) {

                      request.setAttribute(mapping.getAttribute(), instance);

                  } else {

                      HttpSession session = request.getSession();

                      session.setAttribute(mapping.getAttribute(), instance);

                  }

                 //查找原有的

                  if ("request".equals(scope)) {

                      instance = (ActionForm) request.getAttribute(attribute);

                  } else {

                      session = request.getSession();

                      instance = (ActionForm) session.getAttribute(attribute);

                  }

                 4調(diào)用該Bean實(shí)例的reset()方法重置其狀態(tài)。

                    //ActionForm中的屬性,恢復(fù)到初始時(shí)null,獲取默認(rèn)的初始值

                 5)調(diào)用該Bean實(shí)例相應(yīng)的setter方法,使用請(qǐng)求表單中的數(shù)據(jù)填充Bean的屬性。

                 6)如果起用了validate機(jī)制,則調(diào)用表單Beanvalidate()方法。如果validate()方法返回任何錯(cuò)誤,則跳過(guò)步驟7)轉(zhuǎn)到預(yù)定的出錯(cuò)處理頁(yè)面。

                 7)將該表單Bean實(shí)例作為參數(shù),傳給處理器對(duì)象的execute()方法并執(zhí)行。

                  Person person=new Person();

                  person.serUsernmae("zhang");

                  person.setPsw("tonggang")

                  request.setAttribute("person",person)

                  Person person=(Person)request.getAttribute("person");

                  //不存在的情況

                  if(person==null){

                      Person p=new Person();

                      request.setAttribute("person",p)

                  }else{

                  //存在的情況下 reset

                  person.setUsernmae(null)l

                  pserson.setPsw(null);

                  

                  System.out.println(persoon.getUsername()); //zhang

                  }

                  

          /////////////////////////////////////////////////////////////////////////////////////////////////////// 

                 <a href="${pageContext.request.contextPath}/a.do">test</a>

                 <!-- 中間不做什么工作,直接使用 forward 轉(zhuǎn)到需要頁(yè)面-->

               <action path="/a" forward="/success.jsp"></action>

                  優(yōu)點(diǎn):

                 <a href="${pageContext.request.contextPath}/success.jsp">test</a>

          //////////////////////////////////////////////////////////////////////////////////////////////////////  

          3.

          下面是非常重要的DispatchAction,在項(xiàng)目中非常有用

          dispatcheAction的使用規(guī)則 

             * 定義的類要繼承 public class EmpAction extends DispatchAction

             * 該類中的方法定義規(guī)則  

                 * 方法名稱自定義(要和jsp頁(yè)面中的參數(shù)的值一致)

                    * 方法的參數(shù)個(gè)數(shù),參數(shù)類型,參數(shù)順序和方法的返回類型要與action中的execute()方法一致

                   

             * jsp頁(yè)面中的使用

                   路徑如下

                    method=save 參數(shù)名稱   method自定義 參數(shù)名稱要和<action> parameter屬性的值相同

                         參數(shù)值     save要和EmpAction中的方法名稱相同

                  action="${pageContext.request.contextPath}/empAction.do?method=save"

             * Struts-config.xml文件中的配置如下

                 <!--

                              method=save

                              parameter="method"

                              parameter的值是在jsp頁(yè)面中參數(shù)的名稱,

                                        struts在解析的時(shí)候,根據(jù)parameter參數(shù)的值獲取到method,在獲取到method參數(shù)的值save

                                               * String methodName=mapping.getParameter(); //method;

                                                  * String paramValue=request.getParameter(methodName); //save

                                                  * //調(diào)用action中的save方法

                             

                               -->

                              <action path="/empAction" name="empForm" scope="request"

                                 type="com.itcast.struts.action.EmpAction" parameter="method">

                              </action>

          3.下午講的Struts標(biāo)簽

          Struts標(biāo)簽離開(kāi)Struts環(huán)境就不能使用了

          使用Struts標(biāo)簽

          1.導(dǎo)入jar

          2.頁(yè)面引入

          <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

          <html:html lang="true">

           <body>

              <html:form action="" method="post" focus="name">

                <table border="0">

                  <tr>

                    <td>用戶名:</td>

                    <td><html:text property="name" /></td>

                  </tr>

                  <tr>

                    <td>密碼:</td>

                    <td><html:password property="password" /></td>

                  </tr>

                  <tr>

                    <td colspan="2" align="center"><html:submit /></td>

                  </tr>

                </table>

              </html:form>

           </body>

          </html:html >

          3.常見(jiàn)錯(cuò)誤及處理:

          FormEmpForm為例,ActionEmpAction為例

          錯(cuò)誤:

          javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action: "/"

             <html:form action="empAction_save" method="post"> Actionstruts-config.xml文件中必須存在對(duì)應(yīng)的action

             <action path="/empAction_save">

             </action>

          javax.servlet.ServletException: javax.servlet.jsp.JspException:

                Form bean not specified on mapping for action: "empAction_save.do"

           原因缺少name="empForm"

           <action path="/empAction_save" name="empForm" scope="request">

           </action>

           --異常

           javax.servlet.ServletException: javax.servlet.jsp.JspException:

                 No getter method for property: "username" of bean: "com.itcast.struts.form.EmpForm"

                                                標(biāo)簽:

             使用標(biāo)簽的源代碼 , struts的解析的過(guò)程中,已經(jīng)到strutc-config.xml文件中找到對(duì)應(yīng)得信息

             該標(biāo)簽中action屬性的值是必須的   focus="psw" 當(dāng)頁(yè)面運(yùn)行的時(shí)候,光標(biāo)自動(dòng)停留在那個(gè)組件上

             <html:form action="empAction_save.do" method="post" focus="psw">

             標(biāo)簽轉(zhuǎn)化后的代碼

           <form name="empForm" method="post" action="/itcast1130strutstaglib/empAction_save.do"> 

             對(duì)應(yīng)的配置文件:

               <action path="/empAction_save" name="empForm" scope="request">

               </action>

            總結(jié):                         action                                      method         name

                    <html:form>標(biāo)簽        empAction_save.do                             post          無(wú)

                    <form>標(biāo)簽              /itcast1130strutstaglib/empAction_save.do     post          empForm(配置文件中name屬性的值)

                   

           ///////////////////////////////////////////////////////////////////////////////////////////////

           使用標(biāo)簽的源代碼 :

                 <html:text property="username" />

           標(biāo)簽轉(zhuǎn)化后的代碼:

                  <input type="text" name="username" value=""> 

                  //////////////////////////// ActionForm給屬性賦初值

                  private String username="tonggang";

                  <input type="text" name="username" value="tonggang"></td>

                   

                                      property                   name

                <html:text>標(biāo)簽         username

                <input>標(biāo)簽                                            username

           /////////////////////////////////////////////////////////////////////////////////////////////// 

           使用標(biāo)簽的源代碼 :

             <html:password property="psw" />

           標(biāo)簽轉(zhuǎn)化后的代碼:

           <input type="password" name="psw" value="" redisplay="false"> 

           redisplay="false" 不執(zhí)行ActionForm getPsw()方法

           redisplay="true"   執(zhí)行ActionForm  getPsw()方法

           ///////////////////////////////////////////////////////////////////////////////////////////////

             使用標(biāo)簽的源代碼 :

           <html:textarea property="des" cols="10" rows="5"/>

             標(biāo)簽轉(zhuǎn)化后的代碼:

           <textarea name="des" cols="10" rows="5"></textarea>

           /////////////////////////////////////////////////////////////////////////////////////////////

               使用標(biāo)簽的源代碼 : html:radio 使用該標(biāo)簽時(shí) value的屬性必須賦值

              <html:radio property="sex" value=""></html:radio>

                 <html:radio property="sex" value=""></html:radio>

                    標(biāo)簽轉(zhuǎn)化后的代碼:          

               <input type="radio" name="sex" value="">

               <input type="radio" name="sex" value="">

            //////////////////////////////////////////////////////////////////////////////////////////////////

                使用標(biāo)簽的源代碼

                <html:checkbox property="love" value="美容"></html:checkbox>美容

                  <html:checkbox property="love" value="籃球"></html:checkbox>籃球

                  標(biāo)簽轉(zhuǎn)化后的代碼:

               <input type="checkbox" name="love" value="美容">美容

                  <input type="checkbox" name="love" value="籃球">籃球            

            //////////////////////////////////////////////////////////////////////////////////////////////////

                         

                    使用標(biāo)簽的源代碼

                          <html:select property="edu">

                             <html:option value="博士">博士</html:option>

                             <html:option value="碩士">碩士</html:option>

                             <html:option value="本科">本科</html:option>

                             <html:option value="小學(xué)">小學(xué)</html:option>

                           </html:select>

                     標(biāo)簽轉(zhuǎn)化后的代碼:                

                  <select name="edu">

                             <option value="博士">博士</option>

                             <option value="碩士">碩士</option>

                             <option value="本科">本科</option>

                             <option value="小學(xué)">小學(xué)</option>

                  </select>        

            //////////////////////////////////////////////////////////////////////////////////////////////////

             使用標(biāo)簽的源代碼           

                      <td> <html:submit>保存</html:submit> <html:submit value="保存"></html:submit></td>

                        <td> <html:reset value="重置"></html:reset></td>

             標(biāo)簽轉(zhuǎn)化后的代碼:       

                    <td> <input type="submit" value="保存"> <input type="submit" value="保存"></td>

                        <td> <input type="reset" value="重置"></td>       

                           

                        

          Link標(biāo)簽

          <%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>

          <%@ page import="com.itcast.bean.Person "%>

          <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

          <!--

             html:link標(biāo)簽的使用

          轉(zhuǎn)化后的<a href="/itcast1130strutstaglib/welcome.do">action</a>

          -->

          <html:link action="welcome.do">action</html:link><br>

          <!-- <a href="welcome.do">action</a> -->

          <html:link href="welcome.do">href</html:link><br>

          <!-- forward屬性的值是struts-config.xml文件中的全局forward   <forward name="welcomeforward" path="/welcome.jsp"></forward>-->

          <html:link forward="welcomeforward">forward</html:link><br>

          <!-- <a href="/itcast1130strutstaglib/welcome.jsp">page</a> -->

          <html:link page="/welcome.jsp">page</html:link><br>

          <%

             String user_name="zhang";

             pageContext.setAttribute("username",user_name);

          %><br>

          <!-- <a href="/itcast1130strutstaglib/welcome.do?username124=zhang">paramaction</a><br> -->

          <!--

              paramId 表示參數(shù)的名稱

              paramName 表示參數(shù)的值 值用jstl表示${username} 但在Struts中直接書(shū)寫就可以了

              paramName="username" 就是 pageContext.setAttribute("username",user_name);username(key)

           -->

          <html:link action="welcome.do" paramId="username124" paramName="username">paramaction</html:link><br>

          <!--<a href="/itcast1130strutstaglib/welcome.jsp?username124=zhang">paramaforward</a><br>-->

          <html:link forward="welcomeforward" paramId="username124" paramName="username">paramaforward</html:link><br>

          <!-- <a href="welcome.do?username124=zhang">parama=href</a><br> -->

          <html:link href="welcome.do" paramId="username124" paramName="username" >parama=href</html:link><br>

          <br>

          <br>

          <br>

          <br>

          <%

           Person p=new Person();

           p.setName("xupeicheng");

           pageContext.setAttribute("person",p);

          %>

          <!-- <a href="/itcast1130strutstaglib/welcome.do?name1=xupeicheng">paramaction</a><br> -->

          <!--

              paramId="name1" 表示參數(shù)的名稱

              paramName="person"   表示一個(gè)javaBean

              paramProperty="name" 表示javaBean中的一個(gè)屬性

                   paramName指定的javaBean中獲取paramProperty指定的屬性的值

           -->

          <html:link action="welcome.do" paramId="name1" paramName="person" paramProperty="name" >paramaction</html:link><br>

          <!-- <a href="welcome.do?name1=xupeicheng">paramahref</a><br> -->

          <html:link href="welcome.do" paramId="name1" paramName="person" paramProperty="name" >paramahref</html:link><br>

          <!--<a href="/itcast1130strutstaglib/welcome.jsp?name1=xupeicheng">paramaforward</a><br> -->

          <html:link forward="welcomeforward" paramId="name1" paramName="person" paramProperty="name" >paramaforward</html:link><br>

          5.html:rewrite標(biāo)簽的使用,用于生成url路徑,但并不生成<a>   例子:
          <br>
          <html:rewrite action="welcome.do"></html:rewrite>
          <a href="<html:rewrite action="welcome.do"></html:rewrite>">action</a>

          <br>
          <html:rewrite href="welcome.do"></html:rewrite>
          <a href="<html:rewrite href='welcome.do'></html:rewrite>">href</a>

          <br>
          <html:rewrite forward="welcomeforward"></html:rewrite>
          <a href="<html:rewrite forward="welcomeforward"></html:rewrite>">forward</a>

          <br>
          <html:rewrite page="/welcome.jsp"></html:rewrite>
          <a href="<html:rewrite page="/welcome.jsp"></html:rewrite>">page</a>
          <br>

          <%
             String user_name="zhang";
             pageContext.setAttribute("username",user_name);
          %>

          <br>
          <html:rewrite action="welcome.do" paramId="username1" paramName="username"></html:rewrite>
          <a href="<html:rewrite action="welcome.do" paramId="username1" paramName="username"></html:rewrite>">action</a>

          <br>

          <br>
          <html:rewrite href="welcome.do"   paramId="username1" paramName="username"></html:rewrite>
          <a href="<html:rewrite href="welcome.do"   paramId="username1" paramName="username"></html:rewrite>">href</a>

          <br>
          <html:rewrite forward="welcomeforward"  paramId="username1" paramName="username"></html:rewrite>
          <a href="<html:rewrite forward="welcomeforward"  paramId="username1" paramName="username"></html:rewrite>">forward</a>

          <br>
          <html:rewrite page="/welcome.jsp"  paramId="username1" paramName="username"></html:rewrite>
          <a href="<html:rewrite page="/welcome.jsp"  paramId="username1" paramName="username"></html:rewrite>">page</a>



          <%
            Person p=new Person();
            p.setName("xupeicheng");
            pageContext.setAttribute("person",p);
           
          %>


          <br>
          <html:rewrite action="welcome.do" paramId="name1" paramName="person" paramProperty="name"></html:rewrite>
          <a href="<html:rewrite action="welcome.do" paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>">action</a>

          <br>

          <br>
          <html:rewrite href="welcome.do"   paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>
          <a href="<html:rewrite href="welcome.do"   paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>">href</a>

          <br>
          <html:rewrite forward="welcomeforward"  paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>
          <a href="<html:rewrite forward="welcomeforward"  paramId="name1" paramName="person"></html:rewrite>">forward</a>

          <br>
          <html:rewrite page="/welcome.jsp"  paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>
          <a href="<html:rewrite page="/welcome.jsp"  paramId="name1" paramName="person"  paramProperty="name"></html:rewrite>">page</a>

          posted on 2010-01-16 02:36 d66380022 閱讀(2861) 評(píng)論(0)  編輯  收藏
          主站蜘蛛池模板: 健康| 环江| 镇沅| 铜川市| 聂拉木县| 锦州市| 博客| 齐河县| 福海县| 化德县| 鹤庆县| 贡嘎县| 饶平县| 潮州市| 翁源县| 定南县| 蒙城县| 肇源县| 泗洪县| 哈密市| 察雅县| 德州市| 运城市| 嘉黎县| 河南省| 阿合奇县| 北安市| 宜君县| 汶上县| 高陵县| 富锦市| 澄江县| 灵石县| 吉首市| 昌宁县| 宁陕县| 千阳县| 易门县| 屯昌县| 宝鸡市| 西和县|