下面是上传:
myUpload=new FileUpload();
Calendar now = Calendar.getInstance();
String sj2 = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH)+1)+"-"+now.get(Calendar.DAY_OF_MONTH)+" "+now.get(Calendar.HOUR_OF_DAY)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND);
String sj = user_id.trim()+"_"+now.get(Calendar.YEAR)+(now.get(Calendar.MONTH)+1)+now.get(Calendar.DAY_OF_MONTH)+now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+now.get(Calendar.SECOND);
String filePath=getServletConfig().getServletContext().getRealPath("/")+"upload/"+company_id;
java.io.File myFilePath=new java.io.File(filePath);
if(!myFilePath.exists()){
myFilePath.mkdir();
}
String path=getServletConfig().getServletContext().getRealPath("/")+"upload/"+company_id;
out.println(path);
myUpload.setSavePath(path);
myUpload.setNewname(sj);
myUpload.doUpload(request,response);
if(myUpload.isUpload()){ String filename= myUpload.getNewname()+"."+myUpload.getFileext();
String ext= myUpload.getFileext();
long size = myUpload.getFsize();
out.println(filename);
if( ext.compareTo("exe")==0 || ext.compareTo("bat")==0 || ext.compareTo("msi")==0){
// out.println(sqlbean.showMsg("addfile.jsp","因为您上载的文件大于16M!/或者上载的文件不符合要求<br>为系统所不允许,请重新上载!","出错通知!"));
}else{
String title= myUpload.getFieldValue("title");
xx_id= myUpload.getFieldValue("xx_id");
xx_kind= myUpload.getFieldValue("xx_kind");
String content= myUpload.getContentType();
String fname = path +"\\"+filename; String ip= request.getRemoteAddr();
try{
rs=null;
String sql02 = "insert into sw_other_jx_xx_files(xx_id,xx_kind,employee_id,employee_dept,title,filename,filetype,upload_date,ip,contenttype,company_id)values('"
+xx_id+"','"
+xx_kind+"','"
+user_id+"','"
+user_dept+"','"
+title+"','"
+"/upload/"+company_id+"/"+filename+"','"
+ext+"','"
+sj2+"','"
+ip+"','"
+content
+"',"
+company_id+")";
//sql02=new String(sql02.getBytes("ISO8859_1"));
//rs = stmt.executeQuery(sql02);
PreparedStatement perstmt =null;
perstmt = con.prepareStatement(sql02);
perstmt.executeUpdate();
perstmt =null;
}
catch(Exception e)
{ }
}
myUpload=new FileUpload();
Calendar now = Calendar.getInstance();
String sj2 = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH)+1)+"-"+now.get(Calendar.DAY_OF_MONTH)+" "+now.get(Calendar.HOUR_OF_DAY)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND);
String sj = user_id.trim()+"_"+now.get(Calendar.YEAR)+(now.get(Calendar.MONTH)+1)+now.get(Calendar.DAY_OF_MONTH)+now.get(Calendar.HOUR_OF_DAY)+now.get(Calendar.MINUTE)+now.get(Calendar.SECOND);
String filePath=getServletConfig().getServletContext().getRealPath("/")+"upload/"+company_id;
java.io.File myFilePath=new java.io.File(filePath);
if(!myFilePath.exists()){
myFilePath.mkdir();
}
String path=getServletConfig().getServletContext().getRealPath("/")+"upload/"+company_id;
out.println(path);
myUpload.setSavePath(path);
myUpload.setNewname(sj);
myUpload.doUpload(request,response);
if(myUpload.isUpload()){ String filename= myUpload.getNewname()+"."+myUpload.getFileext();
String ext= myUpload.getFileext();
long size = myUpload.getFsize();
out.println(filename);
if( ext.compareTo("exe")==0 || ext.compareTo("bat")==0 || ext.compareTo("msi")==0){
// out.println(sqlbean.showMsg("addfile.jsp","因为您上载的文件大于16M!/或者上载的文件不符合要求<br>为系统所不允许,请重新上载!","出错通知!"));
}else{
String title= myUpload.getFieldValue("title");
xx_id= myUpload.getFieldValue("xx_id");
xx_kind= myUpload.getFieldValue("xx_kind");
String content= myUpload.getContentType();
String fname = path +"\\"+filename; String ip= request.getRemoteAddr();
try{
rs=null;
String sql02 = "insert into sw_other_jx_xx_files(xx_id,xx_kind,employee_id,employee_dept,title,filename,filetype,upload_date,ip,contenttype,company_id)values('"
+xx_id+"','"
+xx_kind+"','"
+user_id+"','"
+user_dept+"','"
+title+"','"
+"/upload/"+company_id+"/"+filename+"','"
+ext+"','"
+sj2+"','"
+ip+"','"
+content
+"',"
+company_id+")";
//sql02=new String(sql02.getBytes("ISO8859_1"));
//rs = stmt.executeQuery(sql02);
PreparedStatement perstmt =null;
perstmt = con.prepareStatement(sql02);
perstmt.executeUpdate();
perstmt =null;
}
catch(Exception e)
{ }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货