模拟资源管理器的小程序<%@ page import="java.io.*,java.util.*" contentType="text/html; charset=GBK"%><html><head>
<title>我的主页</title>
</head><body><%!
String root=null;
String current=null;
%><%
root="e:\\";

current=request.getParameter("current");
if(current == null){
current=root;
}
out.print("<a href=\"main.jsp?current="+root+"\">"+"返回到根"+root+"</a><br>");

if(!current.equals(root)){
String parent=new File(current).getParent();
out.print("<a href=\"main.jsp?current="+parent+"\">"+"返回到上一级"+"</a><br>");
}

out.print("当前路径:"+current+"<br><br><hr>");

File[] fl=new File(current).listFiles();

for(int i=0; i<fl.length; i++){

if(fl[i].isDirectory() && !fl[i].getName().equals("System Volume Information")){
String parent=fl[i].getParent();
out.print("<a href=\"main.jsp?current="+fl[i].getPath()+"\">"+fl[i].getName()+"</a><br>");
}else if(!fl[i].getName().equals("System Volume Information")){
out.print(fl[i].getName()+"<br>");
}
}

%>
</body></html>
一打开包含中文字符的子目录就出错,
帮忙看看如何解决,
谢谢!

解决方案 »

  1.   

    目录名 只能用英文的,中文的不行。 tomcat是iso-8859-1编码。
      

  2.   

    可以修改Tomcat的编码方式,但是最好目录名用英文
      

  3.   

    别老找tomcat的问题看是用什么数据库,tomcat的编码可以改一下通用的utf-8
      

  4.   

    一打开包含中文字符的子目录就出错 -->对中文字符进行 URLEncoder  试试..楼主结贴给分..
      

  5.   

    在你的tomcat底下找到tomcat -> conf -> server.xml 在这一句中添加红色部分
    <Connector connectionTimeout="20000" port="9090" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" /><!--URLEncoding=""--> 表示用你页面的编码方式作为url编码方式,post和get都适合
      

  6.   

    URL是不要传中文,如果URL中的参数有中文,需要转码:java.net.URLEncoder(参数,“GBK”);
      

  7.   

    可以修改tomcat的默认编码,在tomcat的安装目录下的conf/server.xml中修改。   <Connector port="8080" maxHttpHeaderSize="8192"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   connectionTimeout="20000" disableUploadTimeout="true"  crossContext="true" URIEncoding="UTF-8"/>
      

  8.   

    对,可以改成gbk编码,不过最好用英文
      

  9.   

    在tomact里面添加 
    <Connector URIEncoding="GBK" port="8888"/>  
    就ok了
      

  10.   

    出现乱码问题修改配置文件是最不合理的解决方案,因为配置文件的编码是全局的,会影响到整个webserver中所有项目的编码。再说楼主的问题是URL中传中文,改了配置文件不一定可以解决问题。大家可在到google或baidu中搜索两个汉字,观察一下URL的变化
      

  11.   

    current=request.getParameter("current");
    String curr=new String(current.getBytes("iso-8859-1"),"GBK");这是防止得到的current乱码的解决办法  试一下看可以不?