posts - 110, comments - 101, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          前提引入jquery.js

           1$(document).ready(function() {
           2            $('#searchform input').keyup(trimkeyup);
           3}
          );
           4function trimkeyup(e) {
           5    lucene_objInput = $(this);
           6    if (e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13{
           7        var im = $.trim(lucene_objInput.val());
           8        lucene_objInput.val(im); 
           9    }

          10}
                  



           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="請輸入相應(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>

          頁面中所有的input輸入框都會自動過濾前后空格

          posted @ 2011-03-02 17:24 云云 閱讀(6974) | 評論 (5)編輯 收藏

          在數(shù)據(jù)庫中定義長度 那么在代碼中我們做校驗的時候也需要注意
          在數(shù)據(jù)庫中的長度 就是java類的length

          如:VARCHAR2(50 CHAR)
          psInfos.getTruename().length()>50
          用50作邊界

          如:VARCHAR2(100)
           psInfos.getIm().length()>100 用100作邊界

          posted @ 2011-03-02 17:14 云云 閱讀(804) | 評論 (0)編輯 收藏

          如果equals的左邊是空值 會出現(xiàn)空指針異常
          public class Test {
              
          public static void main(String[] args) {
                     String string
          =null;
                     
          if(!string.equals(""))
                     
          {
                         System.out.println(
          "---------");
                     }

              }

              
          }
          Exception in thread "main" java.lang.NullPointerException
              at com.taobao.Test.main(Test.java:
          6)

          如果把可能為空的變量放在右邊 不會有事
           1public class Test {
           2    public static void main(String[] args) {
           3           String string=null;
           4           if(!"ccc".equals(string))
           5           {
           6               System.out.println("---------");
           7           }

           8    }

           9}

          10
          運行結(jié)果 打印出虛線
          ---------

          posted @ 2011-03-02 17:07 云云 閱讀(16095) | 評論 (0)編輯 收藏

          jsp頁面查詢數(shù)據(jù)  取出date類型字段

          java 類
          1     private Date createtime;
          2     private Date updatetime;
           1     public Date getCreatetime()
           2     {
           3         return createtime;
           4     }
           5 
           6     public void setCreatetime(Date createtime)
           7     {
           8         this.createtime = createtime;
           9     }
          10 
          11     public Date getUpdatetime()
          12     {
          13         return updatetime;
          14     }
          15 
          16     public void setUpdatetime(Date updatetime)
          17     {
          18         this.updatetime = updatetime;
          19     }

          jsp頁面:
           1                     <s:if test="jobChangeList.size()>0">
           2                                         <s:iterator value="jobChangeList">
           3                                             <tr>
           4                                                 <td>
           5                                                     <s:date name="createtime" format="yyyy-MM-dd" nice="false" />
           6                                                 </td>
           7                                             </tr>
           8                                         </s:iterator>
           9                                     </s:if>
          10                                     <s:else>沒有相關(guān)記錄</s:else>


          如果要取到時分秒的話 更改一下格式即可:
          <s:date name="networkUserDO.createtime" format="yyyy-MM-dd HH:mm:ss"/>
          結(jié)果:2009-04-16 13:26:29

          posted @ 2011-03-02 16:55 云云 閱讀(5538) | 評論 (0)編輯 收藏

          在jsp頁面使用s:if來判斷 和使用s:date來格式化時間顯示方式



           1                                     <s:if test="jobChangeList.size()>0">
           2                                         <s:iterator value="jobChangeList">
           3                                             <tr>
           4                                                 <td>
           5                                                    <s:if test="employeetype==0">正式員工  </s:if>
           6                                                    <s:elseif test="employeetype==1">外包  </s:elseif>
           7                                                    <s:elseif test="employeetype==2">實習(xí)生</s:elseif>
           8                                                    <s:else></s:else>
           9                                                 </td>
          10                                                 <td>   
          11                                                    <s:if test="dimission==1">在職  </s:if>
          12                                                      <s:elseif test="dimission==2">離職 </s:elseif>
          13                                                   </td>
          14                                             </tr>
          15                                         </s:iterator>

          字符
          <s:iterator value="adboardDOList"> 頁面直接遍歷action提供的數(shù)據(jù)
           
          <td class="align-center"> 
               
          <s:if test='status == "P"'>
                 
          <span class="c-ok">審核通過</span>
               
          </s:if>
                          
          <s:elseif test='status == "W" '>
                            待審核
                          
          </s:elseif>      
                          
          <s:elseif test='status=="R"'>
                            
          <span class="c-warn">審核拒絕</span> <span class="icon icon-warning" title="<s:property value='comments'/>"></span>
                          
          </s:elseif>        
                      
          </td>
          注意 這里如果status類型是字符串類型 在if中外層用的是單引號 里面用雙引號 
          串類型





           1 <s:set name="age" value="61"/> 頁面通過set賦值 同時在頁面上判斷
           2  <s:if test="${age > 60}"> 
           3     老年人 
           4 </s:if>
           5 <s:elseif test="${age > 35}">
           6     中年人
           7 </s:elseif>
           8 <s:elseif test="${age > 15}" id="wawa">
           9     青年人
          10 </s:elseif>
          11 <s:else>
          12     少年
          13 </s:else>
          14 2  從后臺數(shù)據(jù)庫中取出值通過對對象傳到頁面 
          15 <s:if test="psInfoDO.employeetype==0">正式員工  </s:if>
          16 <s:elseif test="psInfoDO.employeetype==1">外包  </s:elseif>
          17 <s:elseif test="psInfoDO.employeetype==2">實習(xí)生</s:elseif>
          18 3
          19 <s:set name="name" value="<%="'"+ request.getParameter("name")+"'" %>"/>
          20 <%
          21   System.out.println(request.getParameter("name"));
          22  %>
          23 <s:if test="#name=='zhaosoft'">
          24   zhaosoft here
          25 </s:if>
          26 <s:elseif test="#name=='zxl'">
          27   zxl here
          28 </s:elseif>
          29 <s:else>
          30   other is here 
          31 </s:else>

          字符串比較的時候 注意加引號 
           

          posted @ 2011-03-02 16:46 云云 閱讀(35972) | 評論 (4)編輯 收藏

          項目中使用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>>真實姓名</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中的時候?qū)ption中的值用一個變量optionValue來保存 這樣在頁面返回后將這個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     }

          posted @ 2011-03-02 14:53 云云 閱讀(11072) | 評論 (6)編輯 收藏

          僅列出標(biāo)題
          共12頁: First 上一頁 4 5 6 7 8 9 10 11 12 
          主站蜘蛛池模板: 孝昌县| 永年县| 阜平县| 开化县| 桃园县| 咸阳市| 随州市| 衡阳市| 集安市| 诏安县| 杭锦后旗| 高台县| 沙河市| 垦利县| 中江县| 嘉禾县| 晴隆县| 仪陇县| 武胜县| 桐柏县| 江都市| 抚顺市| 含山县| 额济纳旗| 尖扎县| 鹤峰县| 准格尔旗| 阳曲县| 谷城县| 临猗县| 云龙县| 卫辉市| 察隅县| 郧西县| 宣武区| 桦南县| 民县| 都匀市| 德令哈市| 太仆寺旗| 睢宁县|