File tree Expand file tree Collapse file tree 6 files changed +146
-0
lines changed
Expand file tree Collapse file tree 6 files changed +146
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .geekgao .file ;
2+
3+ import com .opensymphony .xwork2 .ActionSupport ;
4+
5+ import java .io .*;
6+
7+ public class FileAction extends ActionSupport {
8+
9+ private File file ;
10+ private String fileFileName ;
11+ private String fileContentType ;
12+
13+ public File getFile () {
14+ return file ;
15+ }
16+
17+ public void setFile (File file ) {
18+ this .file = file ;
19+ }
20+
21+ public String getFileFileName () {
22+ return fileFileName ;
23+ }
24+
25+ public void setFileFileName (String fileFileName ) {
26+ this .fileFileName = fileFileName ;
27+ }
28+
29+ public String getFileContentType () {
30+ return fileContentType ;
31+ }
32+
33+ public void setFileContentType (String fileContentType ) {
34+ this .fileContentType = fileContentType ;
35+ }
36+
37+ public String upFile () throws IOException {
38+ if (file == null ) {
39+ return INPUT ;
40+ }
41+
42+ FileInputStream inFile = new FileInputStream (file );
43+ FileOutputStream outFle = new FileOutputStream (new File ("/home/geekgao/" + fileFileName ));
44+ byte [] b = new byte [8192 ];
45+ int bLength ;
46+
47+ while (-1 != (bLength = inFile .read (b ))) {
48+ outFle .write (b ,0 ,bLength );
49+ }
50+ inFile .close ();
51+ outFle .close ();
52+ return SUCCESS ;
53+ }
54+
55+ public String downFile () {
56+ return SUCCESS ;
57+ }
58+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+
3+ <!DOCTYPE struts PUBLIC
4+ "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
5+ "http://struts.apache.org/dtds/struts-2.3.dtd">
6+
7+ <struts >
8+ <constant name =" struts.multipart.maxSize" value =" 1000000000" />
9+ <package name =" UpAndDown" namespace =" /" extends =" struts-default" >
10+ <action name =" file_*" method =" {1}File" class =" com.geekgao.file.FileAction" >
11+ <result name =" input" >
12+ /{1}File.jsp
13+ </result >
14+
15+ <result name =" success" >
16+ /index.jsp
17+ </result >
18+ </action >
19+ </package >
20+ </struts >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <web-app xmlns =" http://xmlns.jcp.org/xml/ns/javaee"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
5+ version =" 3.1" >
6+ <filter >
7+ <filter-name >struts2</filter-name >
8+ <filter-class >org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class >
9+ </filter >
10+ <filter-mapping >
11+ <filter-name >struts2</filter-name >
12+ <url-pattern >/*</url-pattern >
13+ </filter-mapping >
14+ </web-app >
Original file line number Diff line number Diff line change 1+ <%--
2+ Created by IntelliJ IDEA.
3+ User: geekgao
4+ Date: 15-7-25
5+ Time: 上午10:29
6+ To change this template use File | Settings | File Templates.
7+ --%>
8+ <%@ page contentType =" text/html;charset=UTF-8" language =" java" %>
9+ <html >
10+ <head >
11+ <title ></title >
12+ </head >
13+ <body >
14+
15+ </body >
16+ </html >
Original file line number Diff line number Diff line change 1+ <%--
2+ Created by IntelliJ IDEA.
3+ User: geekgao
4+ Date: 15-7-25
5+ Time: 上午10:13
6+ To change this template use File | Settings | File Templates.
7+ --%>
8+ <%@ page contentType =" text/html;charset=UTF-8" language =" java" %>
9+ <html >
10+ <head >
11+ <title ></title >
12+ </head >
13+ <body >
14+ <a href =" file_up" >上传文件</a >
15+ <a href =" file_down" >下载文件</a >
16+ </body >
17+ </html >
Original file line number Diff line number Diff line change 1+ <%@ taglib prefix =" s" uri =" /struts-tags" %>
2+ <%--
3+ Created by IntelliJ IDEA.
4+ User: geekgao
5+ Date: 15-7-25
6+ Time: 上午10:29
7+ To change this template use File | Settings | File Templates.
8+ --%>
9+ <%@ page contentType =" text/html;charset=UTF-8" language =" java" %>
10+ <html >
11+ <head >
12+ <title ></title >
13+ </head >
14+ <body >
15+ <form action =" file_up" method =" post" enctype =" multipart/form-data" >
16+ <s:file name =" file" label =" 上传" ></s:file >
17+ <s:submit type =" submit" ></s:submit >
18+ </form >
19+ <s:debug ></s:debug >
20+ </body >
21+ </html >
You can’t perform that action at this time.
0 commit comments