Jsp表单编码
我有一个jsp页面(比方说page1.jsp),它有一个带有action =“page2.jsp”的html表单。 在 page1.jsp 和 page2.jsp 中,我在 head 部分之外有 <%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
在 head 部分。
如果我以在 url(get 方法) 中看到的形式写希腊字母,类似这样 http://localhost:8080//addProblem.jsp?lastNameForm=%CF%84%CF%85%CE%B8%CF%84%CF%85%CE%B8%CF%84%CF%85& ;firstNameForm=&eMa ....
和 page2.Jsp 中使用 <% out.println(request.getParameter("lastNameForm")); %>
我明白了αÏδαÏδ
我能做些什么?
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 thathttp://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 of <% out.println(request.getParameter("lastNameForm")); %>
i get this αÏδαÏδ
What can i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,您希望使用
UTF-8
字符编码对GET
请求参数进行 URL 解码。对于 URL 解码 GET 请求参数,您需要在服务器配置中设置字符编码。如何执行此操作取决于相关服务器,最好是使用关键字 "uri 编码"。例如,在 Tomcat 中,您需要在server.xml
中为 HTTP 请求设置
元素的URIEncoding
属性,另请参阅此文档:HttpServletRequest#setCharacterEncoding() Bozho 提到的
仅适用于参数包含在请求正文中而不是 URL 中的POST
请求。有关更多背景信息和所有解决方案的详细概述,您可以找到 这篇文章很有用。
Thus, you want to URL-decode
GET
request parameters usingUTF-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 theURIEncoding
attribute of the<Connector>
element for HTTP requests in theserver.xml
, also see this document:The
HttpServletRequest#setCharacterEncoding()
as Bozho mentioned only works forPOST
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.
尝试
在第二个 jsp 的顶部
try
at the top of your 2nd jsp