Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

encoding problem, please help  RSS feed

Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I am using tomcat3.3/servlet2.2/Jsp1.1, linux server
I am making some Japanese html, JSP pages, and I specify all the encoding to be "Shift-JIS" by
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=shift_jis">or
<%@ page contentType="text/html; charset=shift_jis" %>
I am using servlet to read input from request and instore them into DB. I find everything seems to be working fine if all user sessions start and end normally. But I find that if a user close the browser and leave the session unfinished, I find that the encoding seem to be changing.
When my servlet creates the first session, a ISO-8859-1 session is created, but if a user leave the session unfinished, next time it seems my servlet creates a Shift-Jis session, then all my request.getParameter() return corrupted data.
I feel confused about those international encodings. I think for Tomcat3.3, if there is no previous request, it creates a default ISO-8859-1 encoding session, but if there is a previous session of the user, tomcat uses the previous encoding. I do not understand why that if one user changes the encoding, it seems my servlet uses the encoding from then on, even to other users requests and sessions.
Here is my JSP page which causes the problem, can someone take a look? after this JSP submits to my servlet, my servlet creates a session, and use request.getParameter to retrive inputs.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<HTML lang="ja">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<link rel="stylesheet" type="text/css" href="../images/manual.css">
<h4 align="center">something</h4>
<body bgcolor="#FFFFFF">
<%@ page contentType="text/html; charset=shift_jis" %>
<%@ page import="mypackage.*" %>
<%@ page import="java.util.*" %>
<%@ page session="false" %>
<%@ page errorPage="../survey/error.jsp" %>
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 1);
// some submit buttons and so on.

When user submits this page, it seems a ISO-8850-1 session is created, but if user close the browser and reaccess the page, a Shift-JIS session is created, then all data input will be corrupted on the server side. The worst is that all other users are affected as well, and my servlet will only create Shift-JIS session from now on, which is not what I want.
What might be wrong? is there anyone who knows internations encoding staff? Or at least can someone point me a good link for those staff?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!