struts1.2 上傳檔案
html:
<form action="uploadrequire.do" method="post" enctype="multipart/form-data" onsubmit="return validataInput()">
<input type="file" id="fileName" name="myfile" />
</form>
struts form:
private FormFile myfile;
public FormFile getMyfile() {
return myfile;
}
public void setMyfile(FormFile myfile) {
this.myfile = myfile;
}
struts action:
public ActionForward uploadcase(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
boolean flag = true;
try {
int number = 0;
String casenumber="0";
ConnectOracleTools contool = new ConnectOracleTools();
Connection con = contool.getConnectionOracle("system", "manager");
String sql = "select * from caseinformation where caseid in (select max(caseid) from caseinformation)";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(sql);
while(result.next())
{
casenumber = result.getString("casenumber");
casenumber = casenumber.substring(4);
}
number = Integer.parseInt(casenumber)+1;
CaseInfoForm caseform = (CaseInfoForm) form;
String caseinformation = request.getParameter("caseinformation");
FormFile file = caseform.getMyfile();
caseform.setFileName("case"+number);
int index = file.getFileName().lastIndexOf(".");
String path = this.getServlet().getServletContext().getRealPath("/caseinfo");
File newfile = new File(path+"//"+caseform.getFileName());
newfile.mkdir();
String saveName = newfile.getPath() + File.separator + caseform.getFileName()+file.getFileName().substring(index);
FileOutputStream fileoutput = new FileOutputStream(saveName);
fileoutput.write(file.getFileData());
String caselink = "caseinfo"+"/"+caseform.getFileName()+"/"+caseform.getFileName()+file.getFileName().substring(index);
String casetype = request.getParameter("casetype");
String userid = request.getParameter("userid");
String keywords = request.getParameter("keywords");
String insertsql="insert into caseinformation (caseid,casenumber,caseinfo,caselink,createdate,casemanagerid,casetype,keywords)values (caseinformation_squ.nextval,'"
+caseform.getFileName()+"','"+caseinformation+"','"+caselink+"',sysdate,'"
+userid+"','"+casetype+"','"+keywords+"')";
stmt.executeUpdate(insertsql);
System.out.println("insertsql====="+insertsql);
con.commit();
con.close();
fileoutput.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return mapping.findForward("fail");
}
return mapping.findForward("ok");
}
<form action="uploadrequire.do" method="post" enctype="multipart/form-data" onsubmit="return validataInput()">
<input type="file" id="fileName" name="myfile" />
</form>
struts form:
private FormFile myfile;
public FormFile getMyfile() {
return myfile;
}
public void setMyfile(FormFile myfile) {
this.myfile = myfile;
}
struts action:
public ActionForward uploadcase(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
boolean flag = true;
try {
int number = 0;
String casenumber="0";
ConnectOracleTools contool = new ConnectOracleTools();
Connection con = contool.getConnectionOracle("system", "manager");
String sql = "select * from caseinformation where caseid in (select max(caseid) from caseinformation)";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(sql);
while(result.next())
{
casenumber = result.getString("casenumber");
casenumber = casenumber.substring(4);
}
number = Integer.parseInt(casenumber)+1;
CaseInfoForm caseform = (CaseInfoForm) form;
String caseinformation = request.getParameter("caseinformation");
FormFile file = caseform.getMyfile();
caseform.setFileName("case"+number);
int index = file.getFileName().lastIndexOf(".");
String path = this.getServlet().getServletContext().getRealPath("/caseinfo");
File newfile = new File(path+"//"+caseform.getFileName());
newfile.mkdir();
String saveName = newfile.getPath() + File.separator + caseform.getFileName()+file.getFileName().substring(index);
FileOutputStream fileoutput = new FileOutputStream(saveName);
fileoutput.write(file.getFileData());
String caselink = "caseinfo"+"/"+caseform.getFileName()+"/"+caseform.getFileName()+file.getFileName().substring(index);
String casetype = request.getParameter("casetype");
String userid = request.getParameter("userid");
String keywords = request.getParameter("keywords");
String insertsql="insert into caseinformation (caseid,casenumber,caseinfo,caselink,createdate,casemanagerid,casetype,keywords)values (caseinformation_squ.nextval,'"
+caseform.getFileName()+"','"+caseinformation+"','"+caselink+"',sysdate,'"
+userid+"','"+casetype+"','"+keywords+"')";
stmt.executeUpdate(insertsql);
System.out.println("insertsql====="+insertsql);
con.commit();
con.close();
fileoutput.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return mapping.findForward("fail");
}
return mapping.findForward("ok");
}
相關文章
- php檔案上傳之多檔案上傳PHP
- 單個檔案上傳和批量檔案上傳
- 檔案上傳
- SpringMVC 單檔案上傳與多檔案上傳SpringMVC
- Java大檔案上傳、分片上傳、多檔案上傳、斷點續傳、上傳檔案minio、分片上傳minio等解決方案Java斷點
- 檔案上傳之三基於flash的檔案上傳
- 前端大檔案上傳/分片上傳前端
- Flask——檔案上傳Flask
- PHP上傳檔案PHP
- JavaScript 檔案上傳JavaScript
- Git上傳檔案Git
- YII檔案上傳
- 檔案上傳概述
- beego上傳檔案Go
- 上傳檔案流程
- 上傳EXCLE檔案
- PHP 檔案上傳PHP
- 檔案上傳漏洞
- MVC檔案上傳 - 使用Request.Files上傳多個檔案MVC
- .NET Core 如何上傳檔案及處理大檔案上傳
- Django檔案上傳 -- 適用於單一小檔案上傳Django
- 上傳檔案的陷阱
- HTTP檔案上傳原理HTTP
- 上傳檔案專題
- PHP 分片上傳檔案PHP
- Java Web 檔案上傳JavaWeb
- WEB漏洞——檔案上傳Web
- Aliyun Oss 上傳檔案
- 使用fileinput上傳檔案
- PHP ftp上傳檔案PHPFTP
- 上傳檔案至GitHubGithub
- 檔案上傳測試
- Linux上傳檔案Linux
- laravel 多檔案上傳Laravel
- ajaxfileupload 檔案上傳
- Ajax 之檔案上傳
- SpringMvc檔案上傳SpringMVC
- PHP--檔案上傳PHP