Lately I have been working on creating a few HTTP services using a Tomcat 7.0 server. The code below is a html file that I used to test my service.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form id="fm" method="post" action="http://localhost:8080
/DataService/ProductData?category=Ser + bø&location=Herlev##Vejle">
<input type="submit" value="Submit">
</form>
</body>
</html>
My problem is regarding the category parameter “Ser + bø”. On the server side it is read as
“Ser bø” with a three spaces instead of a space,”+”,space. As far as I know the problem has likely to do something with encoding. I am using UTF-8 for the request. I have also change the configuration for the Tomcat server so that it uses UTF-8. Any ideas as to what I am doing wrong?
Modifying your form action URL to pass parameters to back-end is not the right way of dealing with forms. The best way to avoid all of that is just to use a separate form parameters instead:
That’s because
URL has it’s own encoding rules, based on RFC 3986. Plus stands for space there. So you should encode your URL prior to passing it to the server, either using JSP or JavaScript. Encoded
+is%2B:In case that it is a user input you will have to use JavaScript to encode it, as described here.