我在提交页面上设置了UTF-8编码。来到servlet后转成GB2312.结果还是乱码..有什么好的办法不让上传的时候中文字会乱码的..??什么编码都试过。上传后的文件名还是乱码..我刚换的IE8。绝对没问题.请大家帮帮忙吧。这问题困扰了很久。谢谢
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
try {
SmartUpload su = new SmartUpload();
su.initialize(config, request, response);
su.setMaxFileSize(1024 * 1024 * 4); //4M
su.upload();
String path = "d:/upload";
for (int i = 0; i < su.getFiles().getCount(); i++) {
com.jspsmart.upload.File file = su.getFiles().getFile(i);
fileName = file.getFileName();
fileName = new String(fileName.getBytes("ISO-8859-1"),"GB2312");
out.print(fileName);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
try {
SmartUpload su = new SmartUpload();
su.initialize(config, request, response);
su.setMaxFileSize(1024 * 1024 * 4); //4M
su.upload();
String path = "d:/upload";
for (int i = 0; i < su.getFiles().getCount(); i++) {
com.jspsmart.upload.File file = su.getFiles().getFile(i);
fileName = file.getFileName();
fileName = new String(fileName.getBytes("ISO-8859-1"),"GB2312");
out.print(fileName);
解决方案 »
- 为什么点击stop tomcat 和 restart tomcat 却关闭不了呢?(急)
- 求高人指教下
- 学习servlet?
- 请教一个关于JavaMail认证的问题
- 在jsp中使用bean的问题
- ajax jsp 页面传参
- 新手问路?
- 征求SAX、DOM、JAXP等关于JAVA & XML的资料(近5000可用分欲送出,来要分吧!NO.1)
- mysql数据库表设计问题
- 问一下大家有没有什么方法可以获取本年所有工作日?
- [页面加载时异常]javax.servlet.ServletException: Exception creating bean of class org.com.jing.web.form: {1}
- 请问一个问题。我的程序执行到PrintWriter out=response.getWriter();这句话,立即跳转到catch而不执行下面的语句。原因是什么。代码在下面,谢谢各位大大了
fileName = new String(fileName.getBytes("ISO-8859-1"));
???.jpg
这里的charset=GB2312 ,我近几天也在看Jsp,刚在书上看到charset和Charset是有区别的,你换大写的试试。
书上说避免汉字出现乱码的方式有两种
1:即将其中出现Charset中的首写字母(C为大写字母)
1:将字符串str用ISO-8895-1重新编码,存储在字节数组中,然后将数组转化为字符串
byte b[] = str.getBytes("ISO-8895-1");
str = new String(b);
http://wudale.bokee.com/3594651.html
可以在前台页面对文件名进行url编码
试试