176142998

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks
             1. <%@ page contentType="text/html; charset=GBK" language="java"%> 
             2.
          <%@taglib prefix="s" uri="/struts-tags"%> 
             3.
          <html> 
             4.
          <head> 
             5.
          <title>s:if標(biāo)簽測(cè)試</title> 
             6.
          </head> 
             7.
          <body> 
             8.
          <s:set name="age" value="29"/> 
             9.
          <s:if test="${age > 60}"> 
            10.     老年人 
            11.
          </s:if> 
            12.
          <s:elseif test="${age > 35}"> 
            13.     中年人 
            14.
          </s:elseif> 
            15.
          <s:elseif test="${age > 15}" id="wawa"> 
            16.     青年人 
            17.
          </s:elseif> 
            18.
          <s:else> 
            19.     少年 
            20.
          </s:else> 
            21.
          </body> 
            22.
          </html> 


          比如登陸模塊
          <s:textfield label="用戶名" name="user.username"/>
          <s:password label="密碼" name="user.password"/>
          這樣寫的話,他會(huì)默認(rèn)換行,可以不換行嗎?

          只要你將它的這個(gè)theme屬性設(shè)成simple那么它就不會(huì)用Struts2的格式了,每個(gè)STRUTS1的標(biāo)簽都有這樣的一個(gè)性!!!!



          問(wèn)題:No result defined for action cn.bbs.nhpop.web.action.ReplyTopic Action and result input 錯(cuò)誤

          意思是說(shuō)沒(méi)定義input的跳轉(zhuǎn)結(jié)果.

              @Override
              
          public String execute() throws Exception {
                  topic 
          = topicService.getTopic(topicId);
                  reply.setTopic(topic);
                  replyService.replyTopic(reply);
                  
          return this.SUCCESS;
              }

          原因:我的cn.bbs.nhpop.web.action.ReplyTopic Action execute方法返回SUCCESS,但是實(shí)際運(yùn)行中出現(xiàn)了錯(cuò)誤(拋了異常),Action并沒(méi)有返回SUCCESS而是返回INPUT(Action出現(xiàn)錯(cuò)誤時(shí)默認(rèn)的返回值),而我的struts.xml配置文件中并沒(méi)有定義與INPUT對(duì)應(yīng)的Result

                  <action name="replyTopic"
                      class
          ="cn.bbs.nhpop.web.action.ReplyTopic">
                      
          <result name="success" type="chain">
                          
          <param name="actionName">listTopicsDetails</param>
                      
          </result>
                  
          </action>

           

          解決方法:你可以添加一個(gè)與INPUT對(duì)應(yīng)的Result或者解決Action方法實(shí)際運(yùn)行中的異常。

          我的Action到底拋了個(gè)什么異常呢?

                  <s:form action="replyTopic">
                      
          <s:hidden name="topicId" value="%{topicId}"></s:hidden>
          <%--            <s:param name="topicId" value="%{topicId}"></s:param>--%>

          </s:form>
          這是我的reply.jsp,開(kāi)始我使用<s:param></s:param>傳topicId,想當(dāng)然的認(rèn)為可以與<s:form></s:form>合用傳參,導(dǎo)致replyTopic Action無(wú)法獲取到topicId的值
              @Override
              
          public String execute() throws Exception {
                  topic 
          = topicService.getTopic(topicId);
                  reply.setTopic(topic);
                  replyService.replyTopic(reply);
                  
          return this.SUCCESS;
              }
          topic為null拋異常。(<s:url action=""><s:param></s:param></s:url>是可以這樣傳參的,但與<s:form></s:form>不行)
          后來(lái)用<s:hidden></s:hidden>代替解決。另外
          <s:hidden name="topicId" value="topicId"></s:hidden>
          value="%{topicId}"切不可省去%{}否則Action中的topicId的值為字符串為"topicId"而不是我希望的int值1,%{topicId}相當(dāng)于
          <s:property value="topicId"/>
          你可以使用%{}或嵌套<s:property>標(biāo)簽。struts2標(biāo)簽的屬性可以接受一個(gè)字符串的值的時(shí)候請(qǐng)大家尤其注意,必須使用%{} 或<s:property>才會(huì)是你想要的值。比如:
          <s:hidden name="topicId" value="%{topicId}"></s:hidden>


                      
          <s:url id="toReply" action="toReply">
                          
          <s:param name="topicId" value="topicId"></s:param>
                      
          </s:url>

                      
          <tr>
                          
          <td height="18" colspan="2">
                              
          &nbsp;
                              
          <s:a href="%{toReply}">回復(fù) </s:a> &nbsp;
                          
          </td>
                      
          </tr>


          <s:select name="page" list="page" listKey="key" listValue="value" value="page"></s:select>

          @SuppressWarnings("unchecked")
           public List<HashMap> getPage(){
            List<HashMap> numPage = new ArrayList<HashMap>();   
            
            for(int i=0;i<10;i++){
             HashMap m=new HashMap();
             m.put("key", i);
             m.put("value", i+1);
             numPage.add(m);
            } 
            return numPage;
            
           }
          posted on 2008-08-01 14:23 飛飛 閱讀(2810) 評(píng)論(2)  編輯  收藏

          Feedback

          # re: s:if標(biāo)簽測(cè)試 2012-05-10 17:30 大幅度
          我認(rèn)為而  回復(fù)  更多評(píng)論
            

          # 3 2012-05-10 17:31 請(qǐng)問(wèn)惡
          阿斯頓  回復(fù)  更多評(píng)論
            


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 东台市| 宕昌县| 嘉祥县| 麻江县| 法库县| 齐齐哈尔市| 汽车| 毕节市| 旌德县| 昌都县| 文化| 大厂| 基隆市| 吉隆县| 贡嘎县| 嘉定区| 刚察县| 大厂| 海原县| 泰州市| 玉树县| 阳城县| 常州市| 海晏县| 潢川县| 乐安县| 喀喇沁旗| 洮南市| 唐山市| 广安市| 汝阳县| 怀安县| 江川县| 萝北县| 灵川县| 娄烦县| 铅山县| 金阳县| 巴中市| 鄂尔多斯市| 柘荣县|