Struts文件上传机制
2021-06-21 06:04
标签:work open 一个 tac success bsp png action oid 单文件上传 1.Action类
2. 3. Struts文件上传机制 标签:work open 一个 tac success bsp png action oid 原文地址:http://www.cnblogs.com/qlqwjy/p/7183419.html action name="fileUp" class="FileUpload.FileUpload">
result>/message.jspresult>
action>
1 package FileUpload;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7
8 import javax.servlet.ServletContext;
9
10 import org.apache.struts2.ServletActionContext;
11
12 import com.opensymphony.xwork2.ActionSupport;
13
14 public class FileUpload extends ActionSupport{
15
16 private File fileName;
17 private String fileNameContentType;
18 private String fileNameFileName;
19
20 public String execute() throws Exception{
21
22 ServletContext servletContext = ServletActionContext.getServletContext();
23 String dir = servletContext.getRealPath("/files/"+fileNameFileName);
24 System.out.println(dir);
1 DOCTYPE html>
2 html>
3 head>
4 meta charset="UTF-8">
5 title>Insert title heretitle>
6 head>
7 body>
8
9 form action="/Struts2FileUpload/fileUp.action" method="post" enctype ="multipart/form-data">
10
11 input type="file" name="fileName" >
12 input type="submit" value="提交">
13 form>
14
15 body>
16 html>
action name="fileUp" class="FileUpload.FileUpload">
result>/message.jspresult>
action>
上一篇:ci上传图片
下一篇:设置chrome忽略网站证书错误