日期:2014-05-18 浏览次数:20709 次
Quote: 引用: 简单写了一个,楼主不明白的问我。 jsp : <s:form action="doUpload" method="POST" enctype="multipart/form-data"> <s:file name="upload" label="File"/> <s:submit value = "Upload" /> </s:form> 就写了一些重点的东西 struts-fileupload.xml <struts> <package name="fileupload" extends="struts-default" namespace="/fileupload"> <action name="doUpload" class="actions.fileupload.FileUploadAction" method="execute"> <result>upload-success.jsp</result> </action> </package> </struts> FileUploadAction.java public Workbook createWorkBook(InputStream is) throws IOException{ if(fileName.toLowerCase().endsWith("xls")){ return new HSSFWorkbook(is); }else if(fileName.toLowerCase().endsWith("xlsx")){ return new XSSFWorkbook(is); }else{ return null; } } public String execute() throws Exception{ Workbook book = createWorkBook(new FileInputStream(upload)); if(null !=book){ if (book.getNumberOfSheets()> 0){
简单写了一个,楼主不明白的问我。 jsp : <s:form action="doUpload" method="POST" enctype="multipart/form-data"> <s:file name="upload" label="File"/> <s:submit value = "Upload" /> </s:form> 就写了一些重点的东西 struts-fileupload.xml <struts> <package name="fileupload" extends="struts-default" namespace="/fileupload"> <action name="doUpload" class="actions.fileupload.FileUploadAction" method="execute"> <result>upload-success.jsp</result> </action> </package> </struts> FileUploadAction.java public Workbook createWorkBook(InputStream is) throws IOException{ if(fileName.toLowerCase().endsWith("xls")){ return new HSSFWorkbook(is); }else if(fileName.toLowerCase().endsWith("xlsx")){ return new XSSFWorkbook(is); }else{ return null; } } public String execute() throws Exception{ Workbook book = createWorkBook(new FileInputStream(upload)); if(null !=book){ if (book.getNumberOfSheets()> 0){
<s:form action="doUpload" method="POST" enctype="multipart/form-data"> <s:file name="upload" label="File"/> <s:submit value = "Upload" /> </s:form>
<struts> <package name="fileupload" extends="struts-default" namespace="/fileupload"> <action name="doUpload" class="actions.fileupload.FileUploadAction" method="execute"> <result>upload-success.jsp</result> </action> </package> </struts>
public Workbook createWorkBook(InputStream is) throws IOException{ if(fileName.toLowerCase().endsWith("xls")){ return new HSSFWorkbook(is); }else if(fileName.toLowerCase().endsWith("xlsx")){ return new XSSFWorkbook(is); }else{ return null; } } public String execute() throws Exception{ Workbook book = createWorkBook(new FileInputStream(upload)); if(null !=book){ if (book.getNumberOfSheets()> 0){