提交表单时,特殊字符变为符号[重复](A special character turns into symbol when form is submitted [duplicate])

编程入门 行业动态 更新时间:2024-10-22 11:09:09
提交表单时,特殊字符变为符号[重复](A special character turns into symbol when form is submitted [duplicate])

这个问题在这里已有答案:

如何将Unicode字符作为JSP / Servlet request.getParameter传递? 4个答案

我有一个页面,其中一个表单,用户必须填写输入,他们的登录自动填入隐藏的输入,我有一个用户登录具有特殊字符(在我的情况下,字符是é )。 提交表单时,特殊字符变为符号é 。 这是我有的:

形成

<input type="hidden" name="Employe" value="<%= employe %>">

当我检查元素时,我可以看到值是rémax

而当我这样做

String employe = request.getParameter("Employe"); System.out.println(employe);

输出是rémax

这似乎不是charset的问题,因为我可以在两个视图中显示特殊字符。 为什么特殊字符未按预期显示?

This question already has an answer here:

How to pass Unicode characters as JSP/Servlet request.getParameter? 4 answers

I have a page with a form where user have to fill inputs, their login are filled automatically in hidden input, and I have a user with a login with a special character (in my case the character is é). And when the form is submitted the special character turns into the symbol é. Here is what I have :

FORM

<input type="hidden" name="Employe" value="<%= employe %>">

when I inspect the element I can see that the value is rémax

And when I do this

String employe = request.getParameter("Employe"); System.out.println(employe);

The output is rémax

This not seems to be an issue with charset because I can display special characters in both views. Why the special character is not displayed as expected ?

最满意答案

尝试将<?xml version="1.0" encoding="UTF-8"?>到页面的开头。

如果这不起作用,您可以尝试以下方法:

这是一个GET请求,服务器未配置为使用UTF-8来解析请求URI。 如果您使用的是Tomcat,请将/conf/server.xml HTTP Connector的URIEncoding属性设置为UTF-8 。 如果是POST请求,则需要确保servletcontainer使用UTF-8对请求主体进行编码。 你可以事先通过request.setCharacterEncoding("UTF-8")来做到这一点。

Try adding <?xml version="1.0" encoding="UTF-8"?> to the very start of the page.

If that doesn't work you might try the following:

It's a GET request and the server isn't configured to use UTF-8 to parse request URI. If you are using Tomcat then set URIEncoding attribute of the HTTP Connector in /conf/server.xml to UTF-8. If it's a POST request, then you need to ensure that the servletcontainer uses UTF-8 to encode the request body. You can do that by request.setCharacterEncoding("UTF-8") beforehand.

更多推荐

字符,employe,max,电脑培训,计算机培训,IT培训"/> <meta name="description&qu

本文发布于:2023-07-23 18:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   符号   特殊字符   special   character

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!