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.
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.
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);
Thanks,There is no method response.setCharacterEncoding(strCharacterSet);I am using Java Version 1.4.2 and Tomcat 4.0.3 in Linux environment,
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.
hello,
Below is the my code for the JSP page. At line System.out.println("content = "+content);
i am getting ह ह ह ह ह ह ह ह ह ह ह ह
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>
Sorry the tagging for the form tag shoul read as<form name="hinditext" method="post" onsubmit="index.jsp">
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
