1. 程式人生 > >雜記-格式化Date默認格式,日期加一天,jstl判斷字符類型,ajax模擬from表單後臺跳轉頁面,jstl訪問數據庫並在頁面顯示

雜記-格式化Date默認格式,日期加一天,jstl判斷字符類型,ajax模擬from表單後臺跳轉頁面,jstl訪問數據庫並在頁面顯示

lena span 格式 edr app msu 顯示 頁面 clas

1.格式化Date默認格式

     String str="Sun Oct 08 22:36:45 CST 2017";
        SimpleDateFormat sdf = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf2
=new SimpleDateFormat("yyyy-MM-dd"); String sDate=sdf2.format(date); System.out.println(sDate);

2.日期加一天

     // 日期加一天
        Format f = new SimpleDateFormat("yyyy-MM-dd");
            Date today = new Date();
            Calendar c = Calendar.getInstance();
            c.setTime(today);
            c.add(Calendar.DAY_OF_MONTH, 
1);// 今天+1天 Date tomorrow = c.getTime(); sj = f.format(tomorrow);

3.jstl不能對字符類型進行判斷,解決方法,將字符轉成int對比數字

     // el判斷char字符報錯如下,由此可見轉為了long類型,如果是數字可以判斷,字符不行
        Cannot convert A of type class java.lang.String to class java.lang.Long

4.ajax訪問後臺無法像提交form表單一樣在後臺跳轉頁面,解決方法,js動態創建表單

       //ajax訪問後臺無法向form表單一樣跳轉頁面,解決方法,動態創建表單
        function formSubmit(a,b,c,d,e) {
            var turnForm = document.createElement("form");   
            //一定要加入到body中!!   
            document.body.appendChild(turnForm);
            turnForm.method = ‘post‘;
            turnForm.action = ‘bk/jumpToDetail‘;
            turnForm.target = ‘_self‘;
            //創建隱藏表單
            var newElement = document.createElement("input");
            newElement.setAttribute("ksid",b);
            newElement.setAttribute("rq",e);
            newElement.setAttribute("ghlb",c);
            newElement.setAttribute("sxwbz",d);
            newElement.setAttribute("sjd",a);
            turnForm.appendChild(newElement);
            
            turnForm.submit();
        }

5.jstl訪問數據庫並在頁面顯示

    <sql:setDataSource var="snapshot" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.1.8:1521:dbname" user="account"  password="pwd"/>
       <sql:query dataSource="${snapshot}" var="result">
           select * from tablename
       </sql:query>

     <table>
      <c:forEach var="row" items="${result.rows}">
        <tr>
          <td><c:out value="${row.id}"/></td>
          <td><c:out value="${row.name}"/></td>
          <td><c:out value="${row.url}"/></td>
        </tr>
      </c:forEach>
    </table>

雜記-格式化Date默認格式,日期加一天,jstl判斷字符類型,ajax模擬from表單後臺跳轉頁面,jstl訪問數據庫並在頁面顯示