复习struts2+jsp上传文件
2014-05-30 22:08
627 查看
有个form
看action
复习+备忘
<form action="upload" id="upForm" method="post"> <input type="file" id="att" name="attachment" accept="img/jpeg"> <input type="submit" value="ok"> </form>
看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/dtds/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>
复习+备忘
相关文章推荐
- jsp/struts1.2/struts2.0文件上传小结
- jsp\struts1.2\struts2 中文件上传
- jsp/struts1.2/struts2 中文件上传
- JSP/Java/Struts实现文件上传
- struts+newxy(新坐标)文件上传,比jspsmart更简单
- struts2+jsp实现文件上传的方法
- jsp\struts1.2\struts2 中文件上传
- Struts2+jsp上传和下载文件
- jsp/struts1.2/struts2 中文件上传
- struts+newxy(新坐标)文件上传,比jspsmart更简单
- jsp\struts1.2\struts2 中文件上传(转)
- struts+newxy(新坐标)文件上传,比jspsmart更简单 作者:胡立新
- 用jsp上传图片文件,存贮到字段类型为blob的流形式代码
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- struts文件上传要点
- 在jsp中使用smartupload组件上传文件
- 简单的JSP文件上传
- 使用Eclipse 3.1 WST编写Struts文件上传
- 再问struts多文件上传的问题
- 如何在Struts中进行文件上传[转载]