There's a form.
<form action= "Upload" id= "Upform" method= "POST" > <input type= "file" id= "att" name= "attachment" accept= "IMG/JP Eg "> <input type=" Submit "value=" OK "></form>
See action
Package action;public class uploadaction extends actionsupport () { private file attachment; private string attachmentcontenttype ; private string attachmentfilename; public file getattachment () { return attachment; } public void setattachment (file attachment) { This.attachment = attachment; } public string getattachmentcontenttype () { return attachmentContentType; } public void setattachmentcontenttype (String Attachmentcontenttype) { this.attachmentContentType = attachmentcontenttype; } public string getattachmentfilename () { return attachmentfilename; } public void Setattachmentfilename (String attachmentfilename) { this.attachmentfilename = attachmentFileName; } public String Upload () { string realpath= Servletactioncontext.getservletcontext (). Getrealpath ("/"); Fileinputstream fis=new fileinputstream (attachment); Fileoutputstream fos=new fileoutputstream (realpath+ "/upload/x.jpg"); Ioutils.copy (Fis, fos); Fos.flush (); Fos.close (); Fis.close (); return null; }}
Struts.xml
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.0//en" "Http://struts.apache.org/dt Ds/struts-2.0.dtd "><struts><constant name=" struts.multipart.maxSize "value=" 1048576 "></ Constant><package name= "struts2" namespace= "/" extends= "Struts-default" > <action name= "Upload" class= " Action. Uploadaction "method=" Upload "></package></struts>
Review + Memo