var upFile = "D:\luceneData\M1\BBS\MyBBS\upload\日本語.txt"
function down() {
document.forms[0].action = "do_download.jsp?delFile="+ upFile;
document.forms[0].method = "post";
document.forms[0].submit();
}
action直接跳向do_download.jsp 不经过servlet
do_download.jsp:
<%@ page contentType="text/html;charset=UTF-8" import="com.macchy.m2.server.plugin.bbs.*" %><%
%>
<%
String filePath = request.getParameter("delFile");
filePath = new String(filePath.getBytes("ISO-8859-1"), "UTF-8");
System.out.println(filePath);
%>
输出结果:
D:/luceneData/M1/BBS/MyBBS/upload/日本?Etxt 怎么解决这个从url传过的参数,取得时候是乱码问题。。
function down() {
document.forms[0].action = "do_download.jsp?delFile="+ upFile;
document.forms[0].method = "post";
document.forms[0].submit();
}
action直接跳向do_download.jsp 不经过servlet
do_download.jsp:
<%@ page contentType="text/html;charset=UTF-8" import="com.macchy.m2.server.plugin.bbs.*" %><%
%>
<%
String filePath = request.getParameter("delFile");
filePath = new String(filePath.getBytes("ISO-8859-1"), "UTF-8");
System.out.println(filePath);
%>
输出结果:
D:/luceneData/M1/BBS/MyBBS/upload/日本?Etxt 怎么解决这个从url传过的参数,取得时候是乱码问题。。
不过request取得的时候就乱码了
<%
request.setCharacterEncoding("utf-8");
%>
这也不好使得
不走SERVLET
怎么FILTER阿
你试过?Filter和servlet不一样的
没servlet同样可以走Filter的
在web.xml文件配一下就好了
<Connector ......中加入
useBodyEncodingForURI="true"
你这个乱码问题不是可以通过简单办法处理的,因为日本2个是正常的.如果我猜得没错的话,当你是奇数个汉字的时候,最后一个字就是乱码.而偶数个是没问题的.(呵呵,很奇怪吧)
解决办法:参数用javascript的encode 两次该参数如:encode(encode(parameter)),然后后台用java模拟javascript的decode方法去decode这个参数.如果我猜错的了话,你就看你的编码设置吧.............
document.forms[0].method = "post";
document.forms[0].submit();为什么还要do_download.jsp?delFile=upFile 这么传呢?
用get方式传中文这样的值时一定要加密然后再解密。所以我建议是在form里加个<input type="hidden" name="delFile" value="">
然后脚本里加上
document.forms[0].delFile.value = upFile ;先试一下吧,如果还不行,大家再讨论!
<Connector ......中加入
useBodyEncodingForURI="true"加这个有什么作用啊
已经被pass了
不好使阿
web.xml也有filter阿
怎么就是乱码呢
知道
关键怎么解决阿
传之前都是正常的 就是request的时候就乱码了
2.格式化非URL地址传参编码:在JSP或Servlet里取值前使用request.setCharacterEnconding("UTF-8");
3.格式化非URL地址传参编码:使用Filter接口,在实现Filter的类里添加request.setCharacterEnconding("UTF-8"),最后在web.xml的web-app节点下添加两个子节点:
<filter>
<filter-name>SecurityFilter</filter-name>--实现Filter的类名
<filter-class>wind.SecurityFilter</filter-class>--具体的类关系
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>--实现Filter的类名
<url-pattern>/admin/*</url-pattern>--作用的路径范围:admin下的所有页面
</filter-mapping>
注:2和3作用一样,分别和1搭配使用
如果用其中一个的话,需要在另一个里调用一下其方法.
看你提交表单的时候用的是post,所以你回到servlet中看看就知道了.
function down() {
document.forms[0].action = "do_download.jsp?delFile="+ encodeURIComponent(upFile); //调用了encodeURIComponent()方法
document.forms[0].method = "post";
document.forms[0].submit();
}