Upload and download of Struts2

Source: Internet
Author: User

Single File Upload

Upload page

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Struts.xml Configuration

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"><struts><constant name="struts.devMode" value="true"></constant><package name="jiangwenwen" namespace="/" extends="struts-default"> <action name="upload" class="cn.jiangwenwen.action.UploadAction" method="fileUpload"> <result name="success">/success.jsp</result> </action></package></struts>

Action class

public class Uploadaction extends actionsupport{//storing uploaded file object private file upload; Uploaded file name private String uploadfilename; Upload the uploader private String author; Public String FileUpload () throws IOException {FileInputStream fis = new FileInputStream (upload); String Path = "d://pic/" +uploadfilename; FileOutputStream fos = new FileOutputStream (path); int flag = 0; while ((Flag=fis.read ())!=-1) {fos.write (flag); } fis.close (); Fos.close (); return SUCCESS; } public File Getupload () {return upload; } public void Setupload (File upload) {this.upload = upload; } public String Getuploadfilename () {return uploadfilename; } public void Setuploadfilename (String uploadfilename) {this.uploadfilename = Uploadfilename; } public String Getauthor () {return author; } public void Setauthor (String author) {this.author = author; } }

Successfully receive page

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Upload and download of Struts2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.