posts - 110, comments - 101, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
          項(xiàng)目中使用struts2 在頁面中提交表單后將查詢結(jié)果顯示在本頁面  但是要求保留輸入框的查詢內(nèi)容  



          jsp頁面
          1     function dosearch() {
          2         if ($("#textValue").val() == "") {
          3                 $("#errortip").html("<font color='#FF0000'>請輸入查詢內(nèi)容</font>");
          4             return false;
          5         }
          6         $('#searchform').submit();
          7     }


           1         <form id="searchform" name="searchform" action="listPsInfo.action" method="post">
           2         <div id="sr" class="b1 mb10">
           3             <ul id="sr_bq">
           4                 <li class="on">
           5                     <div>
           6                         查詢員工信息
           7                     </div>
           8                 </li>
           9             </ul>
          10             <select class="sa_w_tx" style="width: 100px;" id="selectType" name="psInfoDO.name">
          11                   <option value="1" <s:if test="optionValue==1">selected="selected"</s:if>>工號</option>
          12                   <option value="2" <s:if test="optionValue==2">selected="selected"</s:if>>旺旺(花名)</option>
          13                   <option value="3" <s:if test="optionValue==3">selected="selected"</s:if>>真實(shí)姓名</option>
          14                   <option value="4" <s:if test="optionValue==4">selected="selected"</s:if>>郵箱</option>
          15             </select> 
          16             <input type="text" class="sa_w_tx" style="width: 180px;" id="textValue" name="psInfoDO.value" value="<s:property value="psInfoDO.value"/>" maxlength="100" title="請輸入相應(yīng)內(nèi)容  不允許空值" />&nbsp;&nbsp;
          17              <input type="button" value="查詢" class="btn1" id="subform" onclick="dosearch();"/>&nbsp;&nbsp; <div id="errortip"></div>
          18             </form>

          為了保留下拉列表框中的值 處理辦法是在提交表單到action中的時(shí)候?qū)ption中的值用一個(gè)變量optionValue來保存 這樣在頁面返回后將這個(gè)optionValue帶回到
          jsp使用struts2標(biāo)簽s:if 作判斷就可以使用下拉框的值保留了 
          1 <option value="1" <s:if test="optionValue==1">selected="selected"</s:if>>工號</option>


          普通的input輸入框可以使用action中的域模型就可以了

          action:
          1     private IPeoplesoftInfoBO peoplesoftInfoBO;
          2     private PeoplesoftInfoDO psInfoDO;
          3     private PeoplesoftInfoDO querypsInfo;
          4     private String optionValue;


           1     public String listPsInfo() throws Exception {
           2         
           3         this.optionValue=psInfoDO.getName();
           4         this.querypsInfo=peoplesoftInfoBO.findPsInfoByConditions(psInfoDO);
           5     
           6         if(querypsInfo==null)
           7             {
           8                 addFieldError("userLogNameMessage","系統(tǒng)不存在該員工信息,請核對后手工設(shè)置該操作人員的基本信息");
           9             }
          10         return SUCCESS;
          11     }


          評論

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input[未登錄]  回復(fù)  更多評論   

          2012-03-19 12:36 by 123
          123

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input[未登錄]  回復(fù)  更多評論   

          2013-04-14 20:19 by aa
          aa

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input  回復(fù)  更多評論   

          2013-04-18 14:45 by 圣達(dá)菲
          thank you

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input  回復(fù)  更多評論   

          2013-05-14 16:21 by sdsd
          sdsd

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input  回復(fù)  更多評論   

          2015-08-24 14:46 by ef
          efa

          # re: struts2 jsp表單提交后保留表單中輸入框中的值 下拉框select與input  回復(fù)  更多評論   

          2015-09-09 16:40 by sfsfd
          的范德薩發(fā)

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 陵川县| 图们市| 朝阳县| 陵川县| 五台县| 新建县| 巴林左旗| 陆河县| 孙吴县| 中西区| 开化县| 平安县| 武夷山市| 临澧县| 格尔木市| 宜丰县| 金湖县| 瑞昌市| 舞阳县| 庆元县| 阿尔山市| 鄂托克旗| 海淀区| 安宁市| 五河县| 双辽市| 天镇县| 霍城县| 来凤县| 鸡西市| 灵台县| 奉化市| 隆德县| 长泰县| 双江| 哈尔滨市| 大竹县| 平凉市| 新河县| 无锡市| 颍上县|