0

Scenario: I have MYSQL having default as UTF-8. Same is the case with my HTML and JSP pages,they all have UTF-8 as their standard. If I keep the form method as:

form action = "reg" method = "post" accept-charset = " ISO-8859-1,utf-8;q=0.5" enctype = "application/x-www-form-urlencoded" name = "form1" id="form1"
^-------- It works

IF form action = "reg" method = "post" accept-charset=" ISO-8859-1" enctype="application/x-www-form-urlencoded" name="form1" id="form1"

^--------------It works

If form action = "reg" method = "post" accept-charset = "utf-8" enctype = "application/x-www-form-urlencoded" name = "form1" id= "form1" ^-------It doesn't work and instead wildcard like characters are displayed.

PROBLEM STATEMENT: When I redirect HTML page to JSP page and use <% out.println( request.getParameter("name"));%> It displays correctly : جنید

But, when I use String xx=request.getParameter("name"); and then display the string it displays : &#1580 ; &#1606 ;&#1740 ;&#1583 ;

so, except for hard-code, I am not able to put urdu in my database.

I need a solution for: Taking user input from HTML form in URDU e.g: جنید and inserting the same جنید in the database and not &#1580 ;&#1606 ;&#1740 ;&#1583 ; which also corresponds to جنید

Cœur
  • 37,241
  • 25
  • 195
  • 267
Juni
  • 1
  • 2

2 Answers2

0

You should not use String xx=request.getParameter("name"); in place of this you can use String xx= new String(request.getParameter("name"),"<Proper-Encoding>");

Then your String object xx will not get corrupt.

OR

You can use String xx = URLDecoder.decode(request.getParameter("name"),"<Proper-Encoding>")

You are getting correct value by printing request.getParameter("name") because the servlet container already encodes it for you in proper format. And out which is writer in JSP decodes in correct format.

So to save the request.getParameter("name") value in xx you will have to decode it yourself.

You can refer below links for very clear understanding.

Question1

Question2

Blog

Community
  • 1
  • 1
Anurag Anand
  • 500
  • 1
  • 7
  • 13
0

Sorry for late reporting.

The problem was solved by removing the enctype attribute in the form.

Now, i am able to put data in the database and retrieve as well!

Juni
  • 1
  • 2