Hi gang,
I've Html page that looks like:
<HTML>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<BODY onload='document.forms[0].submit();'>
<form name="form" method="post" action="/path/to/some/servlet">
<input type="hidden" name="username" value="麗安"> <!-- UTF-8 characters -->
</form>
</BODY>
</HTML>
As you can see, the content of this page is UTF-8, but I need to send it with GB2312 character encoding, as the servlet that I am sending this page to expects from me GB2312.
Is this a valid scenario? Because in the servlet, I couldn't retive these chines characters back using a filter that sets the character encoding to GB2312!!
I've created a sample Servlet:
package org.daz;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EncodingServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String ENCODING = "GB2312";
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
setCharacterEncoding(request, response);
String username = request.getParameter("username");
System.out.println(username);
}
private void setCharacterEncoding(HttpServletRequest request, HttpServletResponse response)throws IOException{
request.setCharacterEncoding(ENCODING);
response.setCharacterEncoding(ENCODING);
}
}
The output is: 楹��
Please help