Struts上传文件技术
来源:互联网 发布:mac word 导航栏 编辑:程序博客网 时间:2024/04/28 23:45
Struts是应用于Web层的框架,在《潜入浅出Struts》中介绍了Struts的原理与工作流程,掌握了原理之后,还需要掌握Struts的一些具体技术细节。上传文件是我们常用的一个技术,上传图片与文件的原理是相同的。提供一个链接http://blog.csdn.net/muzizhuben/article/details/6444952,可以根据这篇文章更全面的学习Struts文件上传功能。
下面是一个上传文件的具体实现:
UploadActionForm文件
public class UploadActionForm extends ActionForm {private String title;//上传的文件必须采用FormFile声明private FormFile myfile;public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public FormFile getMyfile() {return myfile;}public void setMyfile(FormFile myfile) {this.myfile = myfile;}}
UploadAction代码
/** * 上传Action * @author Administrator * */public class UploadTestAction extends Action {@Overridepublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception { //转换表单UploadActionForm uaf = (UploadActionForm)form; //打印表单上传的文件名System.out.println("fileName=" + uaf.getMyfile().getFileName());//建立一个输出流,将上传的文件传到C盘FileOutputStream fos = new FileOutputStream("c:\\" +uaf.getMyfile().getFileName());//上传文件内容fos.write(uaf.getMyfile().getFileData());fos.flush();fos.close();//转向成功页面return mapping.findForward("success");}}
Struts-config.xml文件
<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"><struts-config><form-beans><form-bean name="uploadForm" type="com.bjpowernode.struts.UploadActionForm"/></form-beans><action-mappings><action path="/upload"type="com.bjpowernode.struts.UploadTestAction"name="uploadForm"scope="request"> <forward name="success" path="/upload_success.jsp"/></action> </action-mappings> <!--控制上传文件的大小 --> <controller maxFileSize="10M"/></struts-config>
Upload.jsp页面
- Struts上传文件技术
- Struts的文件上传
- struts文件上传要点
- Struts的文件上传
- struts文件上传要点
- Struts的文件上传
- Struts的文件上传
- Struts的文件上传
- Struts上传文件笔记
- Struts文件上传
- Struts的文件上传
- 上传文件(struts篇)
- Struts的文件上传
- struts 多文件上传
- struts构建文件上传
- struts多文件上传
- Struts的文件上传
- 使用Struts上传文件
- 关于程序的入口在哪???
- Invoke和BeginInvoke实例详解
- 字符编码之间的转换
- android 游戏导引(1. 建立 OpenGL 项目)
- CyclicBarrier介绍
- Struts上传文件技术
- Java中getAbsolutePath()实例详解
- 快捷配置Log4J打印到控制台
- 苏宁面试(二)
- <iOS>网络编程(一)SOAP, WSDL, Web Service
- Tomcat在Bin目录中启动需要配置的信息
- 网站架构学习笔记之知识点索引
- Sun One Directory Server(LDAP)安装和调整指南
- Redis的安装及使用