Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get parameter in double byte  RSS feed

 
June
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI everyone,
I try to get a parameter value that is double byte. I found on the web advise to do something like this:
String test = request.getParameter("param");
if(test!=null)
out.println("test = "+ new String(test.getBytes("8859_1"), "UTF8"));
That works. However, with this way I have to do that for every parameter I have. I don't know if there is another "global" way that I don't have to do it for each parameter.
I also try the servlet.setCharacterEncoding("UTF8") before getting parameters but this way didn't work.
Please help!
Thank you very much!
june
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are methods for getting all the parameter values at once in one big array so that you can iterate through that array and make changes to every parameter in a nice little loop with a small amount of code. Look up getParameterValues or something like that.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to mess with doing the getBytes to String conversion for every parameter access, you could abstract that processing into a helper class, in a similar manner to my suggestion in this thread in the servlets forum.
 
June
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all for your replies!!
I guess I wasn't clear . I wonder if there is any other methods instead of converting the parameter value to utf8. I read somewhere that this is not a good way though.
Thanks again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!