1.我使用的是 apache-tomcat-7.0.90 用的是 eclipse mar2
首先在 tomcat7.xx中更改
E:\apache-tomcat-7.0.96\conf
中server.xml文件
以下 代码中 存在两个问题
<input type="text" name="username">
<input type="submit" value="提交">
问题1:在提交时 会出现乱码
解决: //请求解决乱码
request.setCharacterEncoding(“utf-8”);
String name = request.getParameter(“username”);
问题2: 在 URL请求中有中文
解决:servlet中 处理 url带有 中文的 问题
//获取请求参数,文件名称
String filename = request.getParameter(“filename”);
try {
filename = new String(filename.getBytes("iso8859-1"),"utf-8");
System.out.println("investors_name="+filename+"======");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
成功 : 只能谷歌 : 火狐 等高级 浏览器 才能达到效果;