我在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>
<!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>
解决方案 »
- crystalReport2008 web for java----passResultSet issue
- jdbc 驱动
- oracle 10g 有没有像sqlserver那样的企业管理器方便查看??
- 问一个struts标签的问题,急用在线等!!!!!!!!!!!!
- 中文文件名下载问题
- 请教如何将查询的结果集保存为Excel文件?
- 江湖告急!!!!关于类的转换问题!!!!
- IText如何显示中文?急!急!急!
- 我不是搞J2EE的,搞个这方面的调查,来者有分。JSP
- 奇怪问题:用request.getParameter("name")为什么传不动呢??
- 请帮忙分析一下java.lang.IndexOutOfBoundsException: Index: 0, Size: 0有什么错误?
- 关于Cannot find bean under name 的异常
// 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的对象进行设置!
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"
需要什么选吧!