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



          jsp頁面
          1     function dosearch() {
          2         if ($("#textValue").val() == "") {
          3                 $("#errortip").html("<font color='#FF0000'>請輸入查詢內容</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>>真實姓名</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="請輸入相應內容  不允許空值" />&nbsp;&nbsp;
          17              <input type="button" value="查詢" class="btn1" id="subform" onclick="dosearch();"/>&nbsp;&nbsp; <div id="errortip"></div>
          18             </form>

          為了保留下拉列表框中的值 處理辦法是在提交表單到action中的時候將option中的值用一個變量optionValue來保存 這樣在頁面返回后將這個optionValue帶回到
          jsp使用struts2標簽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","系統不存在該員工信息,請核對后手工設置該操作人員的基本信息");
           9             }
          10         return SUCCESS;
          11     }


          評論

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

          2012-03-19 12:36 by 123
          123

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

          2013-04-14 20:19 by aa
          aa

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

          2013-04-18 14:45 by 圣達菲
          thank you

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

          2013-05-14 16:21 by sdsd
          sdsd

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

          2015-08-24 14:46 by ef
          efa

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

          2015-09-09 16:40 by sfsfd
          的范德薩發

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


          網站導航:
           
          主站蜘蛛池模板: 司法| 邵阳市| 晴隆县| 张家川| 伊通| 曲阜市| 土默特左旗| 泗水县| 卓尼县| 金门县| 舒城县| 名山县| 手机| 佛坪县| 大化| 韩城市| 镇远县| 大新县| 商城县| 姜堰市| 喀什市| 盘山县| 蒙自县| 东阳市| 手游| 湖南省| 尚志市| 甘肃省| 利津县| 喀喇| 田林县| 互助| 新密市| 南溪县| 冀州市| 黄浦区| 祁门县| 沂源县| 十堰市| 灵山县| 桃源县|