Struts多文件上传
来源:互联网 发布:淘宝商品宣传视频 编辑:程序博客网 时间:2024/05/16 09:29
struts2配置文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><package name="front" namespace="/" extends="struts-default"><action name="upload" class="action.UplodeAction" method="upload"><param name="savePath">/uploadFile</param><result>/success.jsp</result></action></package></struts>
Action配置
package action;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class UplodeAction extends ActionSupport {private String title;private File[] upload;private String[] uploadContentType;private String[] uploadFileName;private String savePath;@Overridepublic String execute() throws Exception {return super.execute();}public String upload() throws Exception {for (int i = 0; i < upload.length; i++) {FileInputStream fis = new FileInputStream(upload[i]);FileOutputStream fos = new FileOutputStream(getSavePath() + "\\" + getTitle()+uploadFileName[i]);byte[] buffer = new byte[1024];int len = 0;while ((len = fis.read(buffer)) > 0) {fos.write(buffer, 0, len);}fos.close();fis.close();}return SUCCESS;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public File[] getUpload() {return upload;}public void setUpload(File[] upload) {this.upload = upload;}public String[] getUploadContentType() {return uploadContentType;}public void setUploadContentType(String[] uploadContentType) {this.uploadContentType = uploadContentType;}public String[] getUploadFileName() {return uploadFileName;}public void setUploadFileName(String[] uploadFileName) {this.uploadFileName = uploadFileName;}public String getSavePath() {return ServletActionContext.getServletContext().getRealPath(savePath);}public void setSavePath(String savePath) {this.savePath = savePath;}}
index页面即上传界面的设置
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";%><%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"></head><body><s:form action="/upload" enctype="multipart/form-data"><s:textfield name="title" label="文件名称" /><s:file name="upload" label="选择文件" /><s:file name="upload" label="选择文件" /><s:file name="upload" label="选择文件" /><s:submit value="开始上传" /></s:form></body></html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";%><%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'success.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"></head><body>上传成功!<br /> 文件标题:<s:property value="title" /><br /> 文件为:<s:iterator value="uploadFileName" var="fileName"> <img src="<s:property value="'uploadFile/'+title+ #fileName"/>" /> </s:iterator><s:debug /></body></html>
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>Struts2Uplode</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
0 0
- struts 多文件上传
- struts多文件上传
- Struts多文件上传
- Struts文件上传--2.多文件上传
- struts实现多文件上传
- struts 动态多文件上传
- struts 2多文件上传
- Struts实现多文件上传
- struts多个文件上传。
- struts的多文件上传
- Struts多个文件上传
- Struts中实现多文件上传
- Struts中实现多文件上传
- Struts实现自动多文件上传
- 用Struts上传多个文件
- struts实现多个文件上传功能
- struts中上传多个文件
- Struts 2多文件上传(11)
- Android 后台线程调用前台线程的几种方法
- What’s the difference between a stack and a heap?
- javascript闭包
- ApacheBench(ab)压力测试工具
- 关于函数指针数组与返回数组指针的函数
- Struts多文件上传
- Linux线程笔记
- TQ210编译tslib
- 我的shiro之旅: 十四 shiro 自动登录
- spring mvc 使用jsr-303 @Valid实现bean的字段验证
- 几种开源的TCP/IP协议栈分析
- 宽屏模板做法 - 自适应页面
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(29)-T4模版
- html转pdf文件