首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视 ┆淘宝手机在线充值 ┆淘宝游戏点卡充值 
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>JAVA专区>JSP>使用struts upload包进行文件上传的实例
使用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 &nbsp;
      <input align="left" type="file" name="file1" tabindex="0">
      </p>
    <p><br>
      文件1的描述 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input align="left" type="text" name="file1_desc" tabindex="1">
      <br>
        </p>
    <p><br>
      the second file&nbsp;
      <input align="left" type="file" name="file2" tabindex="2">
      </p>
    <p><br>
      文件2的描述 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input align="left" type="text" name="file2_desc" tabindex="3">
          </p>
    <p><br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 下一页
相 关 文 章   发布商链接
·八步实现JSP报表打印
·基于JSP的ajax用户注册验证代码
·JSP实现统计当前在线人数的实例代码
·祥解JSP中的标签库
·经验总结java利用jacob操作word文件
·Ajax+servlet实现页面无刷新显示随机...
·JSP防止表单重复提交的三种方案
·jsp+ajax技术实现行政区划代码三级关...
·jsp生成验证码图片的程序
·Servlet 采用forward 时,页面出现汉...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·Jsp实现网站用户注册使用激活
·JSP彩色验证码生成实例代码
·Java使用ANT在线编译不用重启...
·jsp利用Session防止表单重复...
·Java防止非法和重复表单提交...
·JSP报表打印的一种简单解决方
·Servlet 采用forward 时,页面
·jsp生成验证码图片的程序
·jsp+ajax技术实现行政区划代...
·JSP防止表单重复提交的三种方
·Ajax+servlet实现页面无刷新...
·经验总结java利用jacob操作wo...
·祥解JSP中的标签库
·JSP实现统计当前在线人数的实
·基于JSP的ajax用户注册验证代
热 门 文 章
·经验总结java利用jacob操作wo...
·jsp+ajax技术实现行政区划代...
·基于JSP的ajax用户注册验证代...
·通过流或利用jspsmartupload....
·jsp利用Session防止表单重复...
·Jsp页面列表组件框架设计
·Java防止非法和重复表单提交...
·Jsp分页组件制作实例,可以解...
·Ajax+servlet实现页面无刷新...
·JSP防止表单重复提交的三种方...
·八步实现JSP报表打印
·JSP上传图片的代码提供
·实现jsp页面二级下拉框联动,...
·实例代码讲解jsp上传图片并过...
·实例讲解jsp生成静态网页代码...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .