必威的官网网络

当前位置:必威的官网-必威体育 > 必威的官网网络 > 下面是页面的详细代码

下面是页面的详细代码

来源:http://www.jlqfjt.com 作者:必威的官网-必威体育 时间:2019-11-23 18:37

点评:多文本的上传在这里前大概达成起来会很复杂,然则自从html5的产出,让其变得极其轻便,上边有个科学的亲自过问,我们能够参见下

关键使用的是<input>的multiple属性

代码如下:

<input type="file" name="multipleFileUpload" multiple />

上面是页面包车型客车事必躬亲代码:

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Solution 4-5: Sending multiple files</title>
</head>
<body>
<form id="myForm"
action="" ENCTYPE="multipart/form-data" METHOD="POST">
<input type="file" name="multipleFileUpload" multiple /> <input
type="submit" value="提交"> <input type="reset" value="重设">
</form>
</body>
</html>

java后台的事必躬亲代码:

代码如下:

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
/**
* Servlet implementation class UploadPhotoServlet
*/
public class UploadPhotoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public UploadPhotoServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String imagePath="c:\uploadFile\Image\" getEachDate() "\";//按日期变动文书夹
File uploadPath=new File(imagePath);
if(!uploadPath.exists()){
uploadPath.mkdirs();
}
File tmp=new File("c:\tmp\");
if(!tmp.exists()){
tmp.mkdirs();
}
DiskFileItemFactory factory=new DiskFileItemFactory ();//成立磁盘工厂
factory.setRepository(tmp);//设置文件缓存路线
factory.setSizeThreshold(10 * 1096 );//将文件保存在内部存储器依然磁盘有的时候文件夹的暗中认可临界角,值为10240,即10kb
ServletFileUpload sfu=new ServletFileUpload(factory);//创立管理工科具
sfu.setSizeMax(10*1024*1024);//服务器端能够接到的最大文件大小,-1代表无上限
String fileName=null;
try {
List<FileItem> list=sfu.parseRequest(request);//解析
if(list.size()<1){
return;
}
for(int j=0;j<list.size();j ){
FileItem item=list.get(j);
fileName=item.getName();
if(fileName.equals("")){
request.getRequestDispatcher("/com/visualizerPhoto.jsp").forward(request, response);
return;
}
int pos=fileName.lastIndexOf(".");//取图片文件格式
if(pos>0){
Date date=new Date();
fileName=imagePath date.getTime() fileName.substring(pos);
}
System.out.println("item:" item);
item.write(new File(fileName));//写到磁盘
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
// 13-11-15
public static String getEachDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 0);
String yesterday = new SimpleDateFormat("yyyy-MM-dd ").format(cal
.getTime());
String[] dates = yesterday.split("-");
String realDate = dates[0].substring(2, 4) "-" dates[1] "-"

  • dates[2];
    return realDate.trim();
    }
    }

上边是效果与利益图:
图片 1

本文由必威的官网-必威体育发布于必威的官网网络,转载请注明出处:下面是页面的详细代码

关键词: betway体育官网

上一篇:现在刚绕明白OFDM正交子载波序列

下一篇:没有了