473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

JSP Java truncates string at the first non-english character

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
4 11628
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Min-Koo Seo | last post by:
Hi. I have a java stored procedure whose spec is as follows: CREATE OR REPLACE FUNCTION DECODE_SEQUENCE(SEQUENCE VARCHAR2) RETURN VARCHAR2 DETERMINISTIC AS LANGUAGE JAVA NAME...
10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
1
by: Kim | last post by:
Hello, I am selecting data from a text file with the following statement: "INSERT INTO SELECT * FROM " & sSource & " IN '' " & _ "'text;Database=" & sPath & ";FMT=Delimited;HDR=No' " & _...
1
by: vbdotnetmania | last post by:
Hi, I'm trying to port java code to c#, I am not too familiar with either so forgive me for what might be a stupid question, I wish to use the java string type rather than the c# one, when I try to...
2
by: Madhusudhanan Chandrasekaran | last post by:
Hi all: When I try to convert a float variable into string via repr() or str() function, i get the value as is, i.e '0.1e-7' in IEEE 754 format. Instead how can force the created string to...
1
by: Bob Rock | last post by:
Hello, using the WriteLine method of the Trace class I noticed that strings containing null characters (i.e. \0) get truncated in the output window at the first null char and anything that...
1
by: rainman33 | last post by:
I am getting this error message in the program I'm working on (line 150), and am wondering what it means? This is an exercise for a college class; just want to declare that; this is not my own work....
5
by: Mike | last post by:
I use MS SQL EXPRESS DB VS 2005, c# Win Application I have problem "The string is non-numeric" with formula CDbl({pr_DajPonudu;1.KolicinskiPopust})/100 * {@NajamProstora}
5
by: creative1 | last post by:
hi, I am new at writing JSP and Servlets. When I compile my serverlet I get follwoing error cannot find mymbol method parseDate(java.lang.String) I have follwoing code: Code: ( text )...
1
by: ahmee | last post by:
this my program code these are my errors below please help me out....guys operater % cannot be applied to java.lang.String.int operater / cannot be applied to java.lang.String.int operater +...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.