81,092
社区成员
发帖
与我相关
我的任务
分享
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
String pathtype =request.getParameter("pathtype");//存放类型
String savepath =request.getParameter("savepath"); //放在哪个盘符
String imgpath =request.getParameter("imgpath");//后面文件夹
String datapath =request.getParameter("datapath");//数据库路径
String bckurl =request.getParameter("bckurl"); //要返回路径
System.out.println("pathtype:"+pathtype);
System.out.println("savepath:"+savepath);
System.out.println("imgpath:"+imgpath);
System.out.println("datapath:"+datapath);
System.out.println("bckurl:"+bckurl);
String imgurl ="";
//String Small_img ="";
try{
String pp=null;
String upto=null;
if(ServletFileUpload.isMultipartContent(request)){
DiskFileItemFactory dff = new DiskFileItemFactory();
dff.setRepository(tmpDir);
dff.setSizeThreshold(10240000);
ServletFileUpload sfu = new ServletFileUpload(dff);
sfu.setFileSizeMax(50000000);
sfu.setSizeMax(10000000);
FileItemIterator fii = sfu.getItemIterator(request);
//int a=0;
while(fii.hasNext()){
FileItemStream fis = fii.next();
String fileName ="";
String path="";
if(!fis.isFormField() && fis.getName().length()>0){
if(fis.getName().lastIndexOf("\\")!=-1){
fileName = fis.getName().substring(fis.getName().lastIndexOf("\\"));
}
else fileName = fis.getName();
Date time=new Date();
String dirTime=String.valueOf(time.getTime());
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
int date = c.get(Calendar.DATE);
if (pathtype.equals("1")){
path=savepath; //String path="F:\\eclise-work\\workspace\\";
}else{
path = request.getRealPath("/dynamic");
//System.out.println("request.getRealPath()=="+request.getRealPath("/"));
}
// path2="\\data\\avatars"; imgpath
long filestr=System.currentTimeMillis();
//path1="data/avatars"; datapath //数据库写入 前路径
imgurl=datapath+"/"+filestr+".jpg"; //数据库写入 文件完整路径
String uploadPath1 = path+imgpath;
System.out.println(imgurl);//数据库存入路径
System.out.println(uploadPath1);//本地的所有路径
if(!new File(uploadPath1).isDirectory())
new File(uploadPath1).mkdirs();
fileName=fileName.substring(fileName.lastIndexOf("."));
int str1=fileName.indexOf("?");
if(str1!=-1){
fileName=fileName.substring(0, str1);
}
BufferedInputStream in1= new BufferedInputStream(fis.openStream());
BufferedOutputStream out1 = new BufferedOutputStream(new FileOutputStream(new File(uploadPath1+"\\"+filestr+fileName)));
Streams.copy(in1, out1, true);
}
}
}
}catch(Exception e){
e.printStackTrace();
}
session.setAttribute("imgurl", imgurl);
response.sendRedirect(bckurl);
}
这个也行,这个也行~~ 我只知道如何获取长高。。
我只知道如何获取长高。。