I have a jsp containing a form which posts to a servlet, when the servlet receives the parameters from the form the pound sign (£) is preceded with the following character Â. So £ becomes £. What is causing this and how can I get round it?
我有一个包含一个发布到servlet的表单的jsp,当servlet从表单接收参数时,井号(£)前面跟着下面的字符Â。所以£变成了£。造成这种情况的原因是什么?如何绕过它?
2 个解决方案
#1
This sounds a lot like a character encoding issue. The response containing the pound sign is being sent in the UTF-8 character set, but is being interpreted in a different character set (probably ISO-8859-1).
这听起来很像字符编码问题。包含井号的响应以UTF-8字符集发送,但正在以不同的字符集(可能是ISO-8859-1)进行解释。
Check what character encoding you are specifying for your JSP, and if the problem still persists, use a sniffer to investigate the response that the form posts, and specifically any character set it specifies. By default the form should use the same character set as the page it was served on, so you should be able to control it by checking the page's character set.
检查您为JSP指定的字符编码,如果问题仍然存在,请使用嗅探器调查表单发布的响应,特别是它指定的任何字符集。默认情况下,表单应使用与其提供的页面相同的字符集,因此您应该能够通过检查页面的字符集来控制它。
#2
What you can do is, in your JSP page before retrieving from request object,set content type for your request.[e.g. request.setCharacterEncoding("utf-8");]
您可以做的是,在从请求对象检索之前的JSP页面中,为您的请求设置内容类型。 request.setCharacterEncoding( “UTF-8”);]
Now you can do request.getParameter("yourParamName");
现在你可以做request.getParameter(“yourParamName”);
I also faced same issue & solved as explained above.
如上所述,我也面临同样的问题并解决了。
#1
This sounds a lot like a character encoding issue. The response containing the pound sign is being sent in the UTF-8 character set, but is being interpreted in a different character set (probably ISO-8859-1).
这听起来很像字符编码问题。包含井号的响应以UTF-8字符集发送,但正在以不同的字符集(可能是ISO-8859-1)进行解释。
Check what character encoding you are specifying for your JSP, and if the problem still persists, use a sniffer to investigate the response that the form posts, and specifically any character set it specifies. By default the form should use the same character set as the page it was served on, so you should be able to control it by checking the page's character set.
检查您为JSP指定的字符编码,如果问题仍然存在,请使用嗅探器调查表单发布的响应,特别是它指定的任何字符集。默认情况下,表单应使用与其提供的页面相同的字符集,因此您应该能够通过检查页面的字符集来控制它。
#2
What you can do is, in your JSP page before retrieving from request object,set content type for your request.[e.g. request.setCharacterEncoding("utf-8");]
您可以做的是,在从请求对象检索之前的JSP页面中,为您的请求设置内容类型。 request.setCharacterEncoding( “UTF-8”);]
Now you can do request.getParameter("yourParamName");
现在你可以做request.getParameter(“yourParamName”);
I also faced same issue & solved as explained above.
如上所述,我也面临同样的问题并解决了。