我在jsp中设计一个select 并在option自动导入d:\upload目录下的所有doc,xls,zip,rar格式的文件怎么实现,我现在只实现了一种格式的文件,代码如下:<%@ page language="java" import="java.io.*,java.sql.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%! 
public String  codeToString(String str){
String s=str;
try{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}catch(Exception e)
{
return s;
}

%><%!
class filetxt implements FilenameFilter{  //格式String strstrstr=null;
filetxt(String s)
{
strstrstr="."+s;
}
public boolean accept(File dir,String name){
return name.endsWith(strstrstr);
}
}
 %>
<html>
  <head>    
    <title>上传文件</title>    </head>    <body >  
  <form action="accepteUploadFilejl.jsp"  method="post" name="up" enctype="multipart/form-data" >
  
  <p align="center">经理上传文件给指定员工 </p> 
  <hr> 
  <table border="1" width="200"> 
  
  <tr > 
  <td align="left" width="25%"><font size=2>员工姓名</font> </td> 
  <td align="left" width="50%"><font size=2>指定文件</font> </td>
   </tr>  
  <tr>   <td><select  name="wenjian" size="1"  >     
  <%
  File file1=new File("D:/upload");
  filetxt file_txt=new filetxt("doc");  //只有doc格式,还想要xls,zip,rar格式的文件怎么实现
  File file[]=file1.listFiles(file_txt);
  for(int i=0 ;i<file.length;i++)
  {out.print(file[i].toString());
  %>  
  <option  value="<%file[i].toString();%>" selected><%=file[i].toString() %> </option> 
  <% }%> 
  
  </select> 
  </td> 
  </tr>  
  <tr align="center">
  <td colspan=2>
  <input type="submit" name ="zd" value="指定">
  </td>
  </tr>
  
</table> 
  </form>  
  </body> 
  
</html>

解决方案 »

  1.   

    JFileChooser chooser = new JFileChooser();
    // Note: source for ExampleFileFilter can be found in FileChooserDemo,
        // under the demo/jfc directory in the JDK.
        ExampleFileFilter filter = new ExampleFileFilter();
        filter.addExtension("jpg");
        filter.addExtension("gif");
        filter.setDescription("JPG & GIF Images");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(parent);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           System.out.println("You chose to open this file: " +
                chooser.getSelectedFile().getName());
        }从上述代码你可以看到,需要使用ExampleFileFilter的对象进行设置!
      

  2.   

    <input type="file" accept="">accept属性列表
    1.accept="application/msexcel"
    2.accept="application/msword"
    3.accept="application/pdf"
    4.accept="application/poscript"
    5.accept="application/rtf"
    6.accept="application/x-zip-compressed"
    7.accept="audio/basic"
    8.accept="audio/x-aiff"
    9.accept="audio/x-mpeg"
    10.accept="audio/x-pn/realaudio"
    11.accept="audio/x-waw"
    12.accept="image/gif"
    13.accept="image/jpeg"
    14.accept="image/tiff"
    15.accept="image/x-ms-bmp"
    16.accept="image/x-photo-cd"
    17.accept="image/x-png"
    18.accept="image/x-portablebitmap"
    19.accept="image/x-portable-greymap"
    20.accept="image/x-portable-pixmap"
    21.accept="image/x-rgb"
    22.accept="text/html"
    23.accept="text/plain"
    24.accept="video/quicktime"
    25.accept="video/x-mpeg2"
    26.accept="video/x-msvideo"
    需要什么选吧!
      

  3.   

    编写一个 过滤器 J2SE API里有 
      

  4.   

    弄4个数组,分别搜索doc、xls、zip、rar,然后把这些数组整合到一个数组中就可以了。
      

  5.   

    楼主的意思是要把上传的文件转换成某一中格式,在jsp页面中显示是吧