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动态创建表单
function formSubmitDept(sjd,ksid,ghlb,sxw,rq,mc,jine,lbmc) { var turnForm = document.createElement("form"); //一定要加入到body中!! document.body.appendChild(turnForm); turnForm.method = 'post'; turnForm.action = 'bk/jumpToDetail'; turnForm.target = '_self'; //创建隐藏表单 var element1 = document.createElement("input"); element1.setAttribute("name","sjd"); element1.setAttribute("type","hidden"); element1.setAttribute("value",sjd); var element2 = document.createElement("input"); element2.setAttribute("name","ksid"); element2.setAttribute("type","hidden"); element2.setAttribute("value",ksid); turnForm.appendChild(element1); turnForm.appendChild(element2); 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>