By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

JSP Java truncates string at the first non-english character

P: n/a
Hi

I have a problem with JSP on websphere 5. When I try save information
with swedish or danish characters, the string is cut where the
first of these characters occurs. The JDK used is 1.3.1

I've tried:

String CUNM = request.getParameter("CUNM").trim();
CUNM = URLDecoder.decode(CUNM,"UTF-8");

and

String CUNM = new String(request.getParameter("CUNM").getBytes("wind ows-1252"));

and

request.setCharacterEncoding("UTF-8"); before I access any parameters,
which returns a servlet error.

Does anybody have a answer, or ideas on this one.

/Erkki
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
sc****************@hotmail.com (knocker) wrote in message news:<73**************************@posting.google. com>...
Hi

I have a problem with JSP on websphere 5. When I try save information
with swedish or danish characters, the string is cut where the
first of these characters occurs. The JDK used is 1.3.1

I've tried:

String CUNM = request.getParameter("CUNM").trim();
CUNM = URLDecoder.decode(CUNM,"UTF-8");

and

String CUNM = new String(request.getParameter("CUNM").getBytes("wind ows-1252"));

and

request.setCharacterEncoding("UTF-8"); before I access any parameters,
which returns a servlet error.

Does anybody have a answer, or ideas on this one.

/Erkki
String CUNM = request.getParameter("CUNM").trim(); Don't do trim(). The behavior is unpredictable.
CUNM = URLDecoder.decode(CUNM,"UTF-8"); Don't do this. Already URLdecoded.
String CUNM = new String(request.getParameter("CUNM").getBytes("wind ows-1252")); Oh no. It's too late. Don't do this.
request.setCharacterEncoding("UTF-8"); before I access any parameters,
which returns a servlet error.

What error? windows-1252 and UTF-8, aren't they contradicting? Or,
are they same?

In you JSP:
page pageEncoding ... Your JSP file's encoding e.g ISO-DANISH-PASTRY
page contentType charset ... UTF-8 will do, or (i don't know :)
<% request.setCharacterEncoding(" ... "); %> ... Same as above.

In your servlet:
response.setContentType("text/html; charset=....");
//ISO-DANISH-PASTRY
request.setCharacterEncoding("..."); //UTF-8 will do
out.println
("<META http-equiv=Content-Type content=\"text/html;
charset=....\">"); //ISO-DANISH-PASTRY

(Sorry, I don't know correct ISO number for Danish.)
Jul 17 '05 #2

P: n/a
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
sc****************@hotmail.com (knocker) wrote in message news:<73**************************@posting.google. com>...
Hi

I have a problem with JSP on websphere 5. When I try save information
with swedish or danish characters, the string is cut where the
first of these characters occurs. The JDK used is 1.3.1

I've tried:

String CUNM = request.getParameter("CUNM").trim();
CUNM = URLDecoder.decode(CUNM,"UTF-8");

and

String CUNM = new String(request.getParameter("CUNM").getBytes("wind ows-1252"));

and

request.setCharacterEncoding("UTF-8"); before I access any parameters,
which returns a servlet error.

Does anybody have a answer, or ideas on this one.

/Erkki
String CUNM = request.getParameter("CUNM").trim(); Don't do trim(). The behavior is unpredictable.


What should I do instead?
CUNM = URLDecoder.decode(CUNM,"UTF-8"); Don't do this. Already URLdecoded.
String CUNM = new String(request.getParameter("CUNM").getBytes("wind ows-1252"));

Oh no. It's too late. Don't do this.


Already noticed that :-)

Problem is that if I do a length check on the parameter it returns 2
if the string is "tr"
request.setCharacterEncoding("UTF-8"); before I access any parameters,
which returns a servlet error. What error? windows-1252 and UTF-8, aren't they contradicting? Or,
are they same?

In you JSP:
page pageEncoding ... Your JSP file's encoding e.g ISO-DANISH-PASTRY
page contentType charset ... UTF-8 will do, or (i don't know :)
<% request.setCharacterEncoding(" ... "); %> ... Same as above.


did : <%@ page language="java" pageEncoding="WINDOWS-1251" %>
can't do "page pageEncoding" returns a
JSPG0063E: Page directive: Invalid attribute, pageEncoding

tried with charset also, but it said "cannot read file"

In your servlet:
response.setContentType("text/html; charset=....");


It won't let me do that. Returns an error...

charset is "windows-1252" and it shows if do put the characters in
a java string like this:

String testStr = "";

And show it if I do:

<%=testStr%>

But the request object cuts the bl---y string if get or post parameter
contains .

I've done escape and URLDecode, but that don't work either...

/Erkki
Jul 17 '05 #3

P: n/a
Let me repeat:

--instructions--------------------------------------------------------

On you JSP page, required entries are:
<%@ page
contentType="text/html; charset=UTF-8"
pageEncoding="your-local-platform-encoding"
....
....
%>
<% request.setCharacterEncoding("UTF-8"); %>

On your servlet:
response.setContentType("text/html;
charset=client-handlable-encoding");
request.setCharacterEncoding("UTF-8");
out.println
("<META http-equiv=Content-Type content=\"text/html;
charset=client-handlable-encoding\">");

-----------------------------------------------------------------------
Don't do trim(). The behavior is unpredictable. What should I do instead?

Love it as is.
JSPG0063E: Page directive: Invalid attribute, pageEncoding Your server doesn't support JSP 1.2, or, simply broken.
tried with charset also, but it said "cannot read file" File? What file?
response.setContentType("text/html; charset=....");

It won't let me do that. Returns an error...

Your server is broken, or, charset value is invalid or having typo.
I've done escape and URLDecode, but that don't work either...

You should not need it.

Appendix:
Check your Java system properties, especially:
user.country=
file.encoding=
and
user.language=

Do they match your local encoding?
Jul 17 '05 #4

P: n/a
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...

First of all let me thank you for your time and effort. This is one
thing that really make loose all the marbles...
Let me repeat:

--instructions--------------------------------------------------------

On you JSP page, required entries are:
<%@ page
contentType="text/html; charset=UTF-8"
pageEncoding="your-local-platform-encoding"
...
...
%>
<% request.setCharacterEncoding("UTF-8"); %>

On your servlet:
response.setContentType("text/html;
charset=client-handlable-encoding");
request.setCharacterEncoding("UTF-8");
out.println
("<META http-equiv=Content-Type content=\"text/html;
charset=client-handlable-encoding\">");

-----------------------------------------------------------------------
I'll try that. But, for give me for saying so, I don't have much hope
since pageEncodning returns the illegal attribute error.
Don't do trim(). The behavior is unpredictable. What should I do instead?

Love it as is.


I'm trying, but it's so hard...;=). No seriously, I'll drop the
trim()...
JSPG0063E: Page directive: Invalid attribute, pageEncoding Your server doesn't support JSP 1.2, or, simply broken.


the former then...
tried with charset also, but it said "cannot read file" File? What file?


The jsp file...
When I set page attribute charset only, it says it can't read the
file. I'll post my code as soon as the holiday is over.
response.setContentType("text/html; charset=...."); It won't let me do that. Returns an error...

Your server is broken, or, charset value is invalid or having typo.


"windows-1252"...
I've done escape and URLDecode, but that don't work either... You should not need it.


I know.

Appendix:
Check your Java system properties, especially:
user.country=
file.encoding=
and
user.language=

Do they match your local encoding?


They should match Western Europe, but I'll recheck.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.