aspose file tools*
The moose likes JSP and the fly likes encoding problem, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "encoding problem, please help" Watch "encoding problem, please help" New topic
Author

encoding problem, please help

Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
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">
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title></title>
<link rel="stylesheet" type="text/css" href="../images/manual.css">
</head>
<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?
thanks.


Sun Certified Programmer for Java Platform
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: encoding problem, please help