中文编码不对试试转化一下public static String toGBK(String str) {
        String temp = str;
        try {
            if (temp == null) {
                temp = "";
            }
            if (temp.equals("null")) {
                temp = "";
            }
            byte[] b = temp.getBytes("ISO8859-1"); 
            str = new String(b, "GBK"); 
        } catch (UnsupportedEncodingException uee) {
        }
        return str;
    }

解决方案 »

  1.   

    转码的问题,以前做JSP时经常遇到,上面的方法你多试几遍就好了。记住,你的JAVA程序采用的是ISO8859-1
      

  2.   

    谢谢上面这位兄台,不过问题还是存在,我的详细代码如下:<%@ page contentType="text/html;charset=GBK" %>
    <%@ page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
    <%
    String updir = "/uploadimg/";
    String filePath = getServletContext().getRealPath(updir) ;
    String picurl = "";
    Utils.Mkdir(filePath); //创建目录
    DiskFileUpload fu = new DiskFileUpload();
    fu.setHeaderEncoding("GBK");
    fu.setSizeMax(1000000000);//图片大小限制为1000M
    fu.setSizeThreshold(4096);
    fu.setRepositoryPath("/tmp");
    List fileItems = fu.parseRequest(request);
    Iterator iter = fileItems.iterator();
    while(iter.hasNext()){
    FileItem item = (FileItem)iter.next();
    if( !item.isFormField() ){
    String name = item.getName();
    name = name.replace('\\','/');
    File fullFile = new File(name); 
    File savedFile = new File(filePath,fullFile.getName());
                   item.write(savedFile);
                   picurl += "/" + fullFile.getName();
    }
    }
    %>picurl的值对了,但是文件上载后保存的文件名总是乱码,不知如何解决。