上传时限制文件类型和文件大小。。。。。。。。
我用servlet来做上传,代码如下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
response.setContentType( "text/html;charset=gb2312 ");
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
String tempfilename = (String) session.getId(); // 会话ID
String path = request.getRealPath( "/ ") + "Accessory/ "; // 取物理路经
File f1 = new File(path, tempfilename); //File对象
int n;
try {
InputStream in = request.getInputStream(); // 取得请求输入流
BufferedInputStream my_in = new BufferedInputStream(in);
FileOutputStream fout = new FileOutputStream(f1);
BufferedOutputStream my_out = new BufferedOutputStream(fout);
byte[] b = new byte[10000];
while ((n = my_in.read(b)) != -1) {
my_out.write(b, 0, n);
}
my_out.flush();
my_out.close();
fout.close();
my_in.close();
in.close();
//读取临时文件f1,从中获取上传文件的名字和上传文件的内容。
&