Struts2多文件的上传
来源:互联网 发布:网络电视要不要机顶盒 编辑:程序博客网 时间:2024/05/23 14:00
Struts2Test.java源代码:
package com.test;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class Struts2Test extends ActionSupport{private String[] picFileName;private File[] pic;public String[] getPicFileName() {return picFileName;}public void setPicFileName(String[] picFileName) {this.picFileName = picFileName;}public File[] getPic() {return pic;}public void setPic(File[] pic) {this.pic = pic;}public String upload() throws IOException {for(int i=0;i<pic.length;i++){File upPic=new File(ServletActionContext.getServletContext().getRealPath("upload"),picFileName[i]);upPic.getParentFile().mkdirs();FileInputStream in=null;FileOutputStream out=null;in=new FileInputStream(pic[i]);out=new FileOutputStream(upPic);byte[] byt=new byte[1024];int len=0;while((len=in.read(byt))!=-1){out.write(byt, 0, len);}}return SUCCESS;}}
struts.xml源代码:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><constant name="struts.devMode" value="true" /><package name="default" extends="struts-default" namespace="/"><action name="hello" class="com.test.Struts2Test" ><result name="success">/success.jsp</result></action></package> </struts>
web.xml源代码:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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>
index.jsp源代码:
<%@ 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"%><html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> </head> <body> <s:form action="hello!upload" enctype="multipart/form-data" method="post"> <!-- enctype="multipart/form-data" 此处是一个很容易忽略的盲点 --> <s:file name="pic" label="上传" /> <s:file name="pic" label="上传"/> <s:file name="pic" label="上传"/> <s:submit value="提交"/> </s:form> </body></html>
success.jsp源代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><html> <head> <base href="<%=basePath%>"> <title>SUCCESS</title> </head> <body> SUCCESS! <br> </body></html>
0 0
- Struts2的多文件上传
- Struts2多文件的上传
- [Struts2]Struts2的文件上传
- Struts2的文件上传
- Struts2的文件上传
- Struts2的文件上传
- struts2的文件上传
- Struts2 的文件上传
- struts2的文件上传
- Struts2文件的上传
- Struts2文件的上传
- struts2的文件上传
- Struts2文件的上传
- struts2的文件上传
- Struts2的文件上传
- struts2文件的上传
- Struts2的文件上传
- struts2 的文件上传
- java复习-类和对象(二)
- java实现邮箱发送功能
- POJ2429 GCD & LCM Inverse
- hdu 4185 Oil Skimming
- hdu 5375 Gray code(DP)
- Struts2多文件的上传
- 2015.08.10总结
- Tempus et mobilius Time and motion栈与队列
- APK防反编译技术
- Web支持可暂停的超大文件上传
- 内核通知链原理及机制
- 04 迷宫寻路
- 高效程序员的狂暴之路
- ToggleButton