• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending characters to server using JSP <form> tag

 
Greenhorn
Posts: 5
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to send č, á, ě using tag <form> in JSP but I got this: Å¡, á, ě . Please can you help me where is the problem in this index.jsp file deployed to Tomcat?:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page</title>
</head><body>
<form>
<input type="text" name="first"/>
<input type="submit" value="Send" "/>
</form>
<%
String s1 = String.valueOf(request.getParameter("first"));
System.out.println(s1);
%>
<%=s1%>

<%= System.getProperty("file.encoding") %>
</body></html>

Does this JSP file works at your application server?
Dave
 
David Krcmarik
Greenhorn
Posts: 5
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some comments. I have tried it on Firefox 4.0.1 and IE 8.0 64 bit. My PC is running 64bit Windows7 and Tomcat 7.0. JDK is 1.6.0_24 and I have used the system property JAVA_TOOL_OPTIONS set to -Dfile.encoding=UTF8. Instead of <form> tag I have tried also <form method="get" accept-charset="UTF-8"> and also <form method="post" accept-charset="UTF-8">. I have also tried the response.setContentType("text/html; charset=UTF-8") and response.setCharacterEncoding("UTF-8"). But nothing helped.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me try to clarify all of that. When you say you want to "send" those characters from a JSP, you are actually talking about the HTML generated by that JSP. You want that HTML to send a request containing those characters. You aren't saying you want the JSP to generate some HTML which contains those characters. Right so far?

Then you have something about "my PC". That's the PC which is running your server, correct? Looking at the PC where the browsers are located isn't going to be relevant. Neither are the browsers, in fact.

So to summarize, if I understand correctly, you want your browser to send a request which contains non-ASCII characters and you want that request to be received correctly in your server. But what is happening instead is, despite your best attempts to configure everything to use UTF-8, something is causing the request to be treated as if it's in some other charset.

Well, first of all this all has nothing to do with the fact that your HTML was generated by a JSP. So the JSP forum isn't the right place for the question. So since your server is Tomcat, I'm going to move it to the Tomcat forum.

I was just working with this exact question the day before yesterday.So I can tell you the answer for Websphere, but not for Tomcat. But essentially you have to tell Tomcat to treat requests as if their charset was UTF-8. It appears that you tried to set Tomcat's file.encoding system property to UTF-8... did that work? You posted a JSP which answers that question but didn't tell us the answer.

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a search of the Tomcat forum and found a few posts which mentioned configuration options like this:



Possibly that might also apply to your problem?
 
David Krcmarik
Greenhorn
Posts: 5
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for reply. Unfortunately it did not help. Anyway your summary was exactly right - simply I want to send non-ascii characters via HTML generated using JSP to server. I have changed the configuration in server.xml as you suggested: <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> . My server runs on port 8081. Just to be exactly precise the body of my page now looks like this:
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String s1 = String.valueOf(request.getParameter("first"));
System.out.println(s1);
%>
<%=s1%> <br/>
<%= System.getProperty("file.encoding") %>

The response for <%= System.getProperty("file.encoding") %> is UTF-8. I have tried it also on JBoss 5.0.1 with the same problem.
What is very interesting the the whole thing works well when I (on JBoss) have similar example but the request.getParameter("first") is managed via getters/setters using Java Beans. When you deploy the JSP page into your server does it work correctly with non-ascii characters?

 
David Krcmarik
Greenhorn
Posts: 5
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It actually helped - forget to restart servers. Thanks a lot! Anyway it works only with <form method="get"> but does not work with <form method="post"> . I have encountered similar problem on some forum but was not solved as well. Anyway I am glad that get method works :-)
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"GET" sends data as part of the URL. The URL is parsed by the server. That's why server configuration settings can be important.

"POST" sends data as part of the content. Content has a MIME type and encoding. So the place to set character set (code page) information would be on the HTML POST element itself. I think the "ACCEPT-CHARSET" attribute is probably the one you want.

 
David Krcmarik
Greenhorn
Posts: 5
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi this does not help. But for POST I have discovered that request.setCharacterEncoding("UTF-8"); works :-) . Thanks all for your helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic