2个回答
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.File"%>
<%
request.setCharacterEncoding("UTF-8");
//-----------------------------------------------------------
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String real=application.getRealPath("/");
String saveDir = application.getRealPath("")+"/Files/";
int maxPostSize = 2000*1024*1024;//
String encoding = "UTF-8";
String fileName = null;
String fileName2 = null;
MultipartRequest multi = null;
MultipartRequest multi2 = null;
try{
multi = new MultipartRequest(request,saveDir,maxPostSize,encoding);
}catch(IOException e){
return;
}
String ContentType="";
Enumeration filesname = multi.getFileNames();
String descs=multi.getParameter("descs");
String staffid=multi.getParameter("staffid");
String yuanName="";//文件原名称
double size=0.0d;//文件大小,以kb为单位
String error="";
while(filesname.hasMoreElements()){
try{
String name = (String)filesname.nextElement();
fileName = multi.getFilesystemName(name);
out.print("<br/>---"+fileName+"--<br/>");
yuanName=fileName.toString();
File f = multi.getFile(name);
size=f.length();
out.print("<br/>文件大小---"+size+"B--<br/>");
ContentType = fileName.substring(fileName.lastIndexOf(".")+1);
File file=new File(saveDir+fileName);
String newFileName="";
newFileName=String.valueOf(new java.util.Date().getTime())+"."+ContentType;
int fileid=0;
if(file.exists()){
file.renameTo(new File(saveDir+newFileName));
%>
<a href="<%=basePath %>Files/<%=newFileName%>">下载</a>
<%
}
else{
error="请选择要上传的文件";
}
}catch(Exception e){ //跳回去
error="请选择要上传的文件22";
}
}
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.File"%>
<%
request.setCharacterEncoding("UTF-8");
//-----------------------------------------------------------
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String real=application.getRealPath("/");
String saveDir = application.getRealPath("")+"/Files/";
int maxPostSize = 2000*1024*1024;//
String encoding = "UTF-8";
String fileName = null;
String fileName2 = null;
MultipartRequest multi = null;
MultipartRequest multi2 = null;
try{
multi = new MultipartRequest(request,saveDir,maxPostSize,encoding);
}catch(IOException e){
return;
}
String ContentType="";
Enumeration filesname = multi.getFileNames();
String descs=multi.getParameter("descs");
String staffid=multi.getParameter("staffid");
String yuanName="";//文件原名称
double size=0.0d;//文件大小,以kb为单位
String error="";
while(filesname.hasMoreElements()){
try{
String name = (String)filesname.nextElement();
fileName = multi.getFilesystemName(name);
out.print("<br/>---"+fileName+"--<br/>");
yuanName=fileName.toString();
File f = multi.getFile(name);
size=f.length();
out.print("<br/>文件大小---"+size+"B--<br/>");
ContentType = fileName.substring(fileName.lastIndexOf(".")+1);
File file=new File(saveDir+fileName);
String newFileName="";
newFileName=String.valueOf(new java.util.Date().getTime())+"."+ContentType;
int fileid=0;
if(file.exists()){
file.renameTo(new File(saveDir+newFileName));
%>
<a href="<%=basePath %>Files/<%=newFileName%>">下载</a>
<%
}
else{
error="请选择要上传的文件";
}
}catch(Exception e){ //跳回去
error="请选择要上传的文件22";
}
}
%>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询