开发者

Jsp form encoding

I have a jsp page(let's say page1.jsp) which have an html form with action="page2.jsp". In page1.jsp and page2.jsp i have <%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> outside the head section and <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> in the head section.

If i write greek letters in the form i see in the url(get method) something like that http://localhost:8080//addProblem.jsp?lastNameForm=%CF%84%CF%85%CE%B8%CF%84%CF%85%CE%B8%CF%84%CF%85&firstNameForm=&eMa ....

and from page2.Jsp with the use 开发者_如何学Cof <% out.println(request.getParameter("lastNameForm")); %>

i get this αÏδαÏδ What can i do?


Thus, you want to URL-decode GET request parameters using UTF-8 character encoding. For URL-decoding GET request parameters you need to set the character encoding in the server configuration. How to do it depends on the server in question, best is to refer its documentation using the keywords "uri encoding". In for example Tomcat you need to set the URIEncoding attribute of the <Connector> element for HTTP requests in the server.xml, also see this document:

<Connector (...) URIEncoding="UTF-8" />

The HttpServletRequest#setCharacterEncoding() as Bozho mentioned only works for POST requests where the parameters are included in the request body instead of in the URL.

For more background information and a detailed overview of all solutions you may find this article useful.


try

request.setCharacterEncoding("utf-8");

at the top of your 2nd jsp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜