Monday, March 26, 2012

request.getparameter returns corrupted characters

When inputs non-unicode characters (such as Japanese, Traditional Chinese),  system may returns corrupted characters during request.getParameter("XXX")

It is because the tomcat uses ISO-8859-1 as the default encoding...

Solutions:
1. By declaring page directive
<%@ page contentType="text/html;charset=UTF-8"%>

OR
2. Set the encoding before calling request.getParameter("XXX") in the page
<% 
request.setCharacterEncoding("UTF-8"); 
request.getParameter("XXX");
request.getParameter("YYY");
%>

Tuesday, March 13, 2012

Code Snippnet: Converting java.util.Date to java.sql.Date


 java.util.Date today = new java.util.Date();
long t = today.getTime();
java.sql.Date dt = new java.sql.Date(t);