问题有点难,高手可以进来看看,解决100分,马上结贴
我在做url重写时遇到中文参数的问题
<rule>
<from> /products/([a-z]+) </from>
<to> /products/index.jsp?product_name=$1 </to>
</rule>
http://localhost/example/products/hello
这样一点问题都没有
但是要是这样就出错
http://localhost/example/products/剥皮香蕉
我想可能是这个配置的问题
<from> /products/([a-z]+) </from>
请教兄弟怎样把上面那句配置成支持中文,我先谢谢了,搞几天了搞不出来
我很着急
------解决方案-------------------- <Connector
port= "8088 " maxThreads= "150 " minSpareThreads= "25 " maxSpareThreads= "75 "
enableLookups= "false " redirectPort= "8443 " acceptCount= "100 "
debug= "0 " connectionTimeout= "20000 "
disableUploadTimeout= "true " URIEncoding= "GBK " />
-----------------------------
tomcat 是这样设置的, 就是加上一个URIEncoding= "GBK "
------解决方案--------------------应该对URL重新编码.你GOOGLE一下
------解决方案--------------------最好不要传中文参数。
确实需要传。需要改动tomcat里面的server.xml文件。
给你抓了个参考:
tomcat里的url中文参数问题一定要设置tomcat的server.xml文件
1) 打开tomcat的server.xml文件,找到区块,加入如下一行:
URIEncoding= "UTF-8 "
完整的应如下:
<Connector
port= "80 " maxThreads= "150 " minSpareThreads= "25 " maxSpareThreads= "75 "
enableLookups= "false " redirectPort= "8443 " acceptCount= "100 "
debug= "0 " connectionTimeout= "20000 "
disableUploadTimeout= "true "
URIEncoding= "UTF-8 "
/>
2)重启tomcat,就OK了。
执行如下jsp页页测试是否成功
tcnchar.jsp
<%@ page contentType= "text/html;charset=UTF-8 "%>
<%@ page import= "java.util.* "%>
<%
String q=request.getParameter( "q ");
q = q == null? "没有值 " : q;
%>
<HTML>
<HEAD> <TITLE> URL Test </TITLE>
<META http-equiv=Content-Type content= "text/html; charset=UTF-8 ">
<META http-equiv=pragma content=no-cache>
<body>
你提交了:
<%=q%>
<br/>
<form action= "tcnchar.jsp " method= "post ">
输入中文: <input type= "text " name= "q "> <input type= "submit " value= "确定 ">
<br/>
<a href= "tcnchar.jsp?q=中国 "> 通过get方式提交 </a>
</form>
</BODY> </HTML>
上面代码中的post方式可以通过Filter来处理
/**EncodingFilter.java*/
public class EncodingFilter implements Filter {
protected FilterConfig filterConfig;
private String targetEncoding = "UTF-8 ";
public void init(FilterConfig config) throws
ServletException {
this.filterConfig = config;
this.targetEncoding = config.getInitParameter( "encoding ");
}
public void doFilter(
ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain filterChain)
throws
IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
request.setCharacterEncoding(