java中的编码
我正在使用 java 应用程序,我想使用以下方法将编码设置为 UTF-8:
request.setCharacterEncoding("UTF-8");
问题在于请求未定义?!
i am using java application and i want to set encoding to UTF-8 using :
request.setCharacterEncoding("UTF-8");
the problem is with the request it is not defined ?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
必须在读取请求参数或读取输入之前设置;因此,如果你事后才这样做,那将不会有任何效果。
此外,如果您使用 Tomcat,您还应该在连接器中将 URIEncoding 设置为 UTF-8,如此
This must be set prior to reading request parameters or reading input; therefore if you are doing it after the fact it will have no effect.
In addition if you are using Tomcat you should also set the URIEncoding to UTF-8 within your connectors as noted in this SO answer.
您想指定响应编码吗?这是通过 ServletResponse 完成的。
Do you want to specify the response encoding? That's done via the ServletResponse.
当您的请求到达服务器时,它已经以特定格式进行编码。您无法在运行时更改请求消息的编码。但是,您可以使用 serCharacterEncoding() 方法。
有关编码的更多信息。
By the time your request arrives on the server, it is already encoded in a specific format. You cannot change the request message's encoding at runtime. However you can change the way the encoding is interpreted at runtime using the serCharacterEncoding() method.
More info on encoding.