提交文件:
<%@ page contentType="text/html; charset=UTF-8" 
language="java" 
import="java.sql.*,java.sql.*,java.io.*,javax.naming.*,javax.sql.*,java.util.Date,java.text.*" 
errorPage="" 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form  name="form1" method="post" action="" ENCTYPE="multipart/form-data">
<input type="hidden" name="ID" value="<%=ID%>">
<input type="FILE" name="R_file" size="30" style="width:350px">
</form>
处理文件:
<%@ page contentType="text/html; charset=UTF-8" 
language="java" 
import="java.sql.*,java.sql.*,java.io.*,javax.naming.*,javax.sql.*,java.util.Date,java.text.*,com.jspsmart.upload.*" 
errorPage="" 
%>
<%
  request.setCharacterEncoding("UTF-8"); 
  com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
  mySmartUpload.initialize(pageContext); 
  mySmartUpload.upload();
  String ID=(String)mySmartUpload.getRequest().getParameter("ID");
  String NAME=(String)mySmartUpload.getRequest().getParameter("NAME");
  out.print(NAME);
%>
String NAME=(String)mySmartUpload.getRequest().getParameter("NAME")接收的中文全是乱码。
请问怎样才能取中文?
谢谢!

解决方案 »

  1.   

    jspsmart对中文的支持不好的,建议用流
    public void forDownload(HttpServletResponse response, String filename)
    throws ExcelHelperException {
    try {
    // 设置输出的格式
    response.reset();
    response.setContentType("application/x-msdownload");
    // 汉字转码
    String dfname = URLEncoder.encode(filename, "UTF8");
    response.addHeader("Content-Disposition", "attachment; filename="
    + dfname);
    ServletOutputStream out = response.getOutputStream();
    // 循环取出流中的数据
    int len;
    // 读到流中
    FileInputStream in = new FileInputStream(path + File.separator
    + fileName);
    byte[] l_data = new byte[1024];
    while ((len = in.read(l_data)) > 0) {
    out.write(l_data, 0, len);
    }
    out.close();
    } catch (Exception e) {
    e.printStackTrace();
    throw new ExcelHelperException("输出下载流时出错");
    } };
      

  2.   

    转码
    new String(mySmartUpload.getRequest().getParameter("NAME").getBytes("GBK"),"ISO-8859-1")
      

  3.   

    String name = new String(myUpload.getRequest().getParameter("bookname").getBytes("ISO-8859-1"),"gb2312");这样转
      

  4.   

    to:3楼和4楼
        都不行,转了还是乱码。
    to:1楼
        能把你的代码改成JSP能用的吗?谢谢
      

  5.   

    页面的编码用gbk,不用转码了!