Reputation: 3783
My simple question is why I cant pass non english parameter with different character encoding through a url like this:
http://my-project-name:8080/something?word=علی
however I can send the parameter using a form with post method but I don't wanna do that & I wanna figure out why I can't do it using get method !
Here are my configurations:
In my web.xml I have:
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>sys.system.EncodingFilter</filter-class>
<init-param>
<param-name>encodings</param-name>
<param-value>US-ASCII, UTF-8, EUC-KR, ISO-8859-15, ISO-8859-1</param-value>
</init-param>
<init-param>
<param-name>inputEncodingParameterName</param-name>
<param-value>ie</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
here is my servlet:
public class EncodingFilter implements Filter {
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
if (response.getCharacterEncoding() == null) {
response.setCharacterEncoding("UTF-8");
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
my jsp header has set properly:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ...
when I want to fetch the paramter word in my controller I have a character encoding, here is my controller:
@RequestMapping(value = "something")
public String stopJob(@RequestParam("word") String word) {
... do something
}
the interesting thing is everything has set properly even when I print
request.getCharacterEncoding();
It returns "UTF-8" to me but the "word" is not proper & It's corrupted. is there anyone here who know about this issue ? thanks !
Upvotes: 0
Views: 294
Reputation: 3783
This problem took tones of time of me & finally I figured out what was the mistake :
the server.xml file which was inside eclipse workspace was not as same as the one the "Runtime Environment" ...
that was crap because the server.xml inside eclipse must be same as "Runtime Environment" has because It loads those configs & copy inside Workspace -> Server folder
so when I figured that out, I did these as you guess:
1) delete "Eclipse -> Window -> Preference -> Runtime Environment" server
2) delete everything inside workspace -> Server folder
3) add again the server from "Eclipse -> Window -> Preference -> Runtime Environment"
4) config the server to boot my project
5) change the server.xml file inside "workspace/Servers/TomcatServerFolderName" directory and add URIEncoding="UTF-8" useBodyEncodingForURI="true" inside my connector
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
and after doing all of this character-encoding works just fine with get method !
Upvotes: 1
Reputation: 1327
To transport arbitrary data via url parameters you have to use the format as it's generated by UrlEncoder with all that % and hex numbers. The encoding in this context difines how the hex numbers are interpeted.
Upvotes: 0
Reputation: 750
Have you set URIEncoding inside your Tomcat see tomcat uriencoding also see this Can not send special characters (UTF-8) from JSP to Servlet: question marks displayed
Upvotes: 1