Unable to get Devnagri/Hindi text from JSP Pages

Hi All,

I am doing one project in which user has to enter text in Devnagri/Hindi in HTML Text box/Text area inside a JSP page. The user entered text has to be processed in another JSP file.

When i want to get the user entered text in another JSP by using String content = request.getParameter("txtContent");

method. I am getting the text "हैम्तद".

I am unable to understand how to get the text. Also what is ह... etc.

Thanks in advance.

[542 byte] By [abhishekpandey_y2ka] at [2007-10-2 6:20:48]
# 1

Hi All,

I am doing one project in which user has to enter text in Devnagri/Hindi in HTML Text box/Text area inside a JSP page. The user entered text has to be processed in another JSP file.

When i want to get the user entered text in another JSP by using

String content = request.getParameter("txtContent");

method. I am getting the text &#2361 &#2376 &#2350 &#2381 &#2340 &#2342

.

I am unable to understand how to get the text. Also what is ह... etc.

Thanks in advance.

abhishekpandey_y2ka at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You should put character set for JSP page request this is can be done by do the following :

request.setCharacterEncoding(strCharacterSet);

/*@strCharacterSet: It is string represents the character set .you can put it windows-1256 */

This is for JDK1.3

In JDK 1.4 you can put this caharcter set in both JSP request and

response in the same method:

request.setCharacterEncoding(strCharacterSet);

response.setCharacterEncoding(strCharacterSet);

HamzehAbuLawia at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thanks,There is no method response.setCharacterEncoding(strCharacterSet);I am using Java Version 1.4.2 and Tomcat 4.0.3 in Linux environment,
abhishekpandey_y2ka at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

for a JSP page, you can use the pageEncoding attribute of the page directive.

<%@ page pageEncoding="ISO-8859-1" %>

For a servlet, HttpServletResponse has a method inherited from ServletResponse called setContentType(String type). You can use it to set the character encoding.

filestreama at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hello,

Below is the my code for the JSP page. At line System.out.println("content = "+content);

i am getting &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361 &#2361

I want to get the text the text as entered by user.

Please help

<%@ page pageEncoding="ISO-8859-1" contentType="text/html" language="java"%>

<html>

<head>

</head>

<body>

<% if((request.getMethod()).equals("POST")) {

String content= new String(request.getParameter("txtContent"));

System.out.println("content = "+content);

} else {

String content = "";

%><form name="hinditext" method="post" onsubmit="index.jsp">

<input type="hidden" name="contentText"/>

<table width="60%">

<tr>

<td width="10%"><b>Text</b></td>

<td width="90%">

<textarea name="txtContent" rows="6" cols="60" title="Enter the alert message"><%=content%></textarea>

</td>

</tr>

<tr>

<td colspan="2" align="center">

<input type="submit" name="Submit" value="Submit"/>

</td>

</tr>

</table>

</form>

<% }

%> </body>

</html>

abhishekpandey_y2ka at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Sorry the tagging for the form tag shoul read as<form name="hinditext" method="post" onsubmit="index.jsp">
abhishekpandey_y2ka at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hi All,

Below is the solution,

<%@page contentType="text/html; charset=UTF-8"%>

<html>

<head>

</head>

<body>

<% if((request.getMethod()).equals("POST")) {

request.setCharacterEncoding("UTF-8");

String paramTmp = request.getParameter("txtContent");

System.out.println("paramTmp = "+paramTmp);

String paramValue = new String(paramTmp.getBytes("ISO-8859-1"), "UTF-8");

System.out.println("paramValue = "+paramValue);

} else {

String content = "";

%><form name="hinditext" method="post" action="index.jsp">

<input type="hidden" name="contentText"/>

<table width="60%">

<tr>

<td width="10%"><b>Text</b></td>

<td width="90%">

<textarea name="txtContent" rows="6" cols="60" title="Enter the alert message"><%=content%></textarea>

</td>

</tr>

<tr>

<td colspan="2" align="center">

<input type="submit" name="Submit" value="Submit"/>

</td>

</tr>

</table>

</form>

<% }

%> </body>

</html>

The main code lines are

<%@page contentType="text/html; charset=UTF-8"%>

and

request.setCharacterEncoding("UTF-8");

Thanks u all

abhishekpandey_y2ka at 2007-7-16 13:22:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...