After searching for 4 straight hours now, I have to give up and ask you guys. I have a very simple form which will take an input and on action, write it to my Oracle DB (which supports 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>
All I want to do is the form to be able to accept characters such as é
or 请
and store them without changing the encoding.
I already have tried (and combined) options such as setting
request.setCharacterEncoding("UTF-8");
or building a new String with encoding parameter:
new String(request.getParameter("NAME").getBytes(), "UTF-8")
but it always ends up in the database like this: �?��??
(Input: 收藏
)
Any help on the subject would be greatly appreciated.
In Tomcat
server.xml
, add aURIEncoding="UTF-8"
attribute to yourConnector
like so:The documentation states:
A useful (slightly related) SO post can be found here.
Have you had a look in the debugger how the string looks like before the insert to the database in java? If it is not mixed up there it is the import function to the database. Which wprapper or utility are you using there?