jsp&Servlet(4)
向java学习人士们提供一个好的学习网站www.java1234.com
Date类型的转成String类型
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.format(date);
String类型转成Date类型
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.parse(str);
easyui对于combobox取值:$('#s_sex').combobox("getValue")
dateBox取值:$('#s_bbirthday').datebox("getValue")
防止乱码:request.setCharacterEncoding("utf-8");
jsonArray 里面装 jsonObject
jsonObject有put(key,value)方法填数据
如果jsonArray已经装了jsonObject 可以使用jsonArray.addAll()方法在往里面装
将 ResultSet 转换成 JSONArray:
public static JSONArray formatRsToJsonArray(ResultSet rs) throws Exception{ ResultSetMetaData md = rs.getMetaData(); int num = md.getColumnCount(); JSONArray array= new JSONArray(); while(rs.next()){ JSONObject mapOfColValues = new JSONObject(); for(int i=1;i<=num;i++){ Object o = rs.getObject(i); if(o instanceof Date){ mapOfColValues.put(md.getColumnName(i), DateUtil.fomatDate((Date)o, "yyyy-MM-dd")); }else{ mapOfColValues.put(md.getColumnName(i), rs.getObject(i)); } } array.add(mapOfColValues); } return array; }
将处理过得东西打包发给前台:
public static void write(HttpServletResponse response,Object o) throws Exception{
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println(o.toString());
out.flush();
out.close();
}
我学习JAVA的母校