作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在连续搜索了四个小时之后,我不得不放弃并询问你们。我有一个非常简单的表单,它将接受输入并执行操作,将其写入我的 Oracle DB(支持 UTF-8)。
<form action="test.jsp" method='GET' accept-charset="UTF-8">
<label for='NAME'>Name</label><input type="text" id="NAME" name="NAME"/>
<button type="submit">Submit</button>
</form>
我想要做的就是表单能够接受 é
或 请
等字符并存储它们而不更改编码。
我已经尝试过(并组合了)选项,例如设置
request.setCharacterEncoding("UTF-8");
或者使用编码参数构建一个新的字符串:
new String(request.getParameter("NAME").getBytes(), "UTF-8")
但它总是以这样的方式结束在数据库中:�?????
(输入: Collection
)
任何有关该主题的帮助将不胜感激。
最佳答案
在 Tomcat server.xml
中,向您的 Connector
添加 URIEncoding="UTF-8"
属性,如下所示:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
可以找到一个有用的(稍微相关的)SO 帖子 here .
关于java - 如何在 servlet 中处理 UTF-8 编码的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6453262/
我是一名优秀的程序员,十分优秀!