好久没用Struts1了 这几天终于闲了下来 翻开了 以前的笔记和代码 有种写写S1代码的冲动 于是先搞了一个S1的单文件上传 练练手 上代码先
首先写了一个upload.jsp
<h1>文件上传</h1>
<html:form action="uploadAction" method="post" enctype="multipart/form-data">
<html:file property="file"/>
<html:submit value="上传"></html:submit>
</html:form>
然后定义了一个简单的UploadForm
private FormFile file ;
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
然后写uploadAction
public class UploadAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
FileForm fileForm = (FileForm) form;
String path = request.getSession().getServletContext().getRealPath("/upload");
FormFile file = fileForm.getFile();
InputStream stream = file.getInputStream();
File pathFile = new File (path);
if(!pathFile .exists() ){
pathFile.mkdirs();
}
FileOutputStream os = new FileOutputStream(path+"/"+file.getFileName());
byte buff[] = new byte[1024*4];
int len = 0 ;
while ((len = stream.read(buff))!=-1){
os.write(buff, 0, len);
}
stream.close();
os.close();
return null;
}
}
然后是在struts-config.xml里面的配置项
<form-beans>
<form-bean name="uploadForm" type="com.blacklee.form.FileForm"></form-bean>
</form-beans>
<action path="/uploadAction" name="uploadForm" type="com.blacklee.action.UploadAction"></action>
到此 一个最简单的文件上传就搞定了 但是还没有解决中文的乱码问题 首先想到了配置中央处理器 。
程序虽然简单 但是好久没有用了 有些淡忘 果然 最淡的墨水也胜过最强的记忆
分享到:
相关推荐
struts1.3.8.chm帮助文档struts1.3.8.chm帮助文档struts1.3.8.chm帮助文档struts1.3.8.chm帮助文档
apache 发布的struts1.3.8的jar包。文件小,方便下载
struts1.3.8文档chm格式,就是将struts中的docs目录中的html转成chm文件
struts1.3.8API CHM struts1.3.8API CHM struts1.3.8API CHM
Struts 1.3.8jar包,共十个。
NULL 博文链接:https://coderdream.iteye.com/blog/1902016
这是struts1.3.8的lib 所有文件 堪称struts1最好用的一个版本
struts 1.3.8 源码 struts 1.3.8 源码 struts 1.3.8 源码 struts 1.3.8 源码
struts1.3.8apps包含了struts1.3.8apps的比较全面的jar包,希望能够给大家学习带来方便
Struts 1.3.8 CHM格式API文档
韩顺平spring 雇员管理系统 struts-1.3.8-lib 所有jar包
赠送Maven依赖信息文件:struts-core-1.3.8.pom; 包含翻译后的API文档:struts-core-1.3.8-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.struts:struts-core:1.3.8; 标签:core、apache、struts、...
我在官方网站上下载不到,所以放到这里,希望能帮到各位。
Spring2.5+Struts1.3.8+Hibernate3.0整合详细配置 希望对初学者有所帮助
Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一
Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案二
自己整理的struts1.3.8+spring2.5.6+hibernate3.3框架集成,项目带jar包,直接导入即可运行。
struts 1.3.8 api 学习struts用得到!
struts1也有比struts2好的地方,如果你的项目还有struts1,这个包应该适合于你。 解压后有3个jar包,引入工程即可使用。
struts-1.3.8-all.zip 官方完整包