tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject RE: GET FORM Encoding Test JSP
Date Tue, 04 Apr 2006 12:59:52 GMT
Beg your pardon, it was in the FAQ and BZ. Connector elements have an attribute available

URIEncoding="UTF-8"

AC.

-----Original Message-----
From: Allistair Crossley [mailto:Allistair.Crossley@QAS.com] 
Sent: 04 April 2006 13:20
To: tomcat-user@jakarta.apache.org
Subject: GET FORM Encoding Test JSP

Hi,

The following JSP presents a well-known problem found all over the web regarding GET form
submissions not encoding form parameters properly. The issue does not exist with POST. 

I have read just about every article on the web about this issue, and the below JSP incorporates
all of the solutions. 

However, it still does not work and I wonder having seen a few suggestions that this could
be the fault of Tomcat, whether there is any truth in this, since an equivalent ASP test does
not exhibit the issue.

I have used the below JSP test with both a SetCharacterEncodingFilter in front, and without
(this is also catered for by the request.setCharacterEncoding call). 

Everything reads UTF-8 except when you submit the word Amélie into the form, the output is
broken. Interestingly, the QENC string which converts the request.getParameter to UTF-8 fixes
the string. This is impracticle I would have thought and should be converted by Tomcat given
the request encoding which is correctly set.

My question - is this a Tomcat bug, a Tomcat caveat, or my own silly fault?

Thanks, Allistair

== snip ==

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page language="java"
contentType="text/html;charset=UTF-8" %> <% request.setCharacterEncoding("UTF-8"); %>
<html>
  <head>
    <title>Form Encoding Test with - Amélie</title>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  </head>
  <body>
  	<p>Submit the form with <b>Amélie</b></p>
  	<p>request.getCharacterEncoding() : <%= request.getCharacterEncoding() %></p>
    <p>response.getCharacterEncoding() : <%= response.getCharacterEncoding() %></p>
    <p>
    <%
    String q = request.getParameter("q");
	String qenc = "";
	if (q != null) {
		qenc = new String(request.getParameter("q").getBytes(), "UTF-8");
	} else {
		q = "";
	}
    %>
	<form method="get" action="/jsp/enctest/index.jsp" accept-charset="UTF-8">
		<input name="q" type="text" value="<%= q %>" />
		<input type="submit" value="Go" />
	</form>
	<p>new String(request.getParameter("q").getBytes(), "UTF-8") : <%= qenc %></p>
   
  </body>
</html>


<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE>
-------------------------------------------------------
QAS Ltd.
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT> <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLACK>
Disclaimer:  The information contained within this e-mail is confidential and may be privileged.
This email is intended solely for the named recipient only; if you are not authorised you
must not disclose, copy, distribute, or retain this message or any part of it. If you have
received this message in error please contact the sender at once so that we may take the appropriate
action and avoid troubling you further.  Any views expressed in this message are those of
the individual sender.  QAS Limited has the right lawfully to record, monitor and inspect
messages between its employees and any third party.  Your messages shall be subject to such
lawful supervision as QAS Limited deems to be necessary in order to protect its information,
its interests and its reputation.  

Whilst all efforts are made to safeguard Inbound and Outbound emails, QAS Limited cannot guarantee
that attachments are virus free or compatible with your systems and does not accept any liability
in respect of viruses or computer problems experienced.
</FONT>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message