Notes-format date default format, date plus day, Jstl judge character type, Ajax simulation from form background jump page, JSTL Access database and display on page

Source: Internet
Author: User



1. Formatting the default format of the 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. Date Plus Day


// date plus one day
         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); // today + 1 day
             Date tomorrow = c.getTime ();
             sj = f.format (tomorrow); 


3.jstl cannot judge a character type, solve a problem, convert a character to an int comparison number


// el judges that the char character is reported as follows, which shows that it is converted to long type.
         Cannot convert A of type class java.lang.String to class java.lang.Long 


4.ajax access to the background can not be like submitting form forms in the background jump page, workaround, JS dynamic creation of forms


// The ajax access background cannot jump to the page like the form form, the solution is to dynamically create the form
         function formSubmit (a, b, c, d, e) {
             var turnForm = document.createElement ("form");
             // Must be added to the body! !!
             document.body.appendChild (turnForm);
             turnForm.method = ‘post’;
             turnForm.action = ‘bk / jumpToDetail’;
             turnForm.target = ‘_self’;
             // Create hidden form
             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 accessing the database and displaying it on the page


 <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>






Notes-format date default format, date plus day, Jstl judge character type, Ajax simulation from form background jump page, JSTL Access database and display on page


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.