| 使用struts upload包进行文件上传的实例 |
| 来源:
发布时间:2007-11-19 发布人:
浏览:
人次
字体:
[大
中
小]
|
|
/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author wdz123@hotmail.com * @version 1.0 */ public class FileLoadActionForm extends ActionForm { /** * 对应fileLoadjsp.jsp 的 <input align="left" type="file" name="file1" tabindex="0"> * 注意类型是FormFile * */ private FormFile file1; private String file1_desc; /** *对应fileLoadjsp.jsp 的 <input align="left" type="file" name="file2" tabindex="2"> * 注意类型是FormFile * */ private FormFile file2; private String file2_desc; public FormFile getFile1() { return file1; }
public void setFile1(FormFile file1) { this.file1 = file1; }
public void setFile2_desc(String file2_desc) { this.file2_desc = file2_desc; }
public void setFile2(FormFile file2) { this.file2 = file2; }
public void setFile1_desc(String file1_desc) { this.file1_desc = file1_desc; }
public String getFile1_desc() { return file1_desc; }
public FormFile getFile2() { return file2; }
public String getFile2_desc() { return file2_desc; }
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { /** @todo: finish this method, this is just the skeleton.*/ return null; }
public void reset(ActionMapping actionMapping, HttpServletRequest servletRequest) { } }
//---------------------end FileLoadActionForm code ----------------------------------
3. struts-config.xml
//---------------------------------------------struts-config.xml --------------
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <form-beans> <form-bean name="fileLoadActionForm" type="structs_file_test.FileLoadActionForm" /> </form-beans> <action-mappings> <action input="/fileLoadjsp.jsp" name="fileLoadActionForm" path="/fileLoadAction" scope="request" type="structs_file_test.FileLoadAction" validate="true"> <forward contextRelative="true" name="home" path="/welcome.jsp" redirect="true" /> </action> </action-mappings> </struts-config>
//---------------------------------------------end struts-config.xml --------------
4.web.xml
//------------------------------------- web.xml -----------------------------------
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>WebModule1</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>application</param-name> <param-value>ApplicationResources</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
//-------------------------------------end web.xml ----------------------------------- 5.fileLoadjsp.jsp
//---------------------------------------- fileLoadjsp.jsp --------------
<%@page contentType="text/html; charset=GB2312"%> <html> <head> <title>fileLoadjsp</title> </head> <body bgcolor="#ffffff"> <h1>structs file load example</h1>
<form name="filelaod" action="/fileLoadAction.do" method="POST" enctype="multipart/form-data"> <p>the first file <input align="left" type="file" name="file1" tabindex="0"> </p> <p><br> 文件1的描述 <input align="left" type="text" name="file1_desc" tabindex="1"> <br> </p> <p><br> the second file <input align="left" type="file" name="file2" tabindex="2"> </p> <p><br> 文件2的描述 <input align="left" type="text" name="file2_desc" tabindex="3"> </p> <p><br> <input type="submit" name="ok" value="提 交"> </p> </form>
<br> <br> <a href="welcome.jsp" tabindex="4">goto home</a> </body> </html>
//----------------------------------------end fileLoadjsp.jsp -------------- 6.welcome.jsp
//------------------------------------------------------welcome.jsp ----------------------------
<%@ page contentType="text/html; charset=GB2312" %> <html> <head> <title> welcome </title> </head> <body bgcolor="#ffffff"> <h1> for test structs file load </h1> <a href="fileLoadjsp.jsp"> goto file load page </a> </body> </html>
共2页: 上一页 [1] 2 下一页
| |
| |
|
|
|
|
| §最新评论:(评论内容只代表网友观点,与本站立场无关!) | |
|
|
|
|
| 注意:请勿在本站发布政治话题、色情及违反法律的内容。 |
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。 |