Struts2的上传
来源:互联网 发布:少女前线索米数据 编辑:程序博客网 时间:2024/05/20 06:07
jsp页面代码:
<div class="upload"><form action="/wemiss/uploadpic.action" method="post" enctype="multipart/form-data" class="picuploadform"><input type="button" class="uploadpic" value="点击上传头像"/><input type="file" class="picfile" name="resourcefile"/><span class="infoshow">照片大小仅支持150*140</span></form></div>
java后台代码:
public String uploadpic(){ String path = session.getServletContext().getRealPath("/uploadfile/");//上传的服务器上的path try {FileInputStream fis = new FileInputStream(resourcefile);//通过临时文件.tmp来拿到文件的输入流 int ishave=0;byte[] b=new byte[1024];File outfile=new File(path);if(!outfile.isDirectory()){outfile.mkdir();}FileOutputStream fos = new FileOutputStream(new File(path,resourcefileFileName));while((ishave=fis.read(b))!=-1){fos.write(b);}fos.close();System.out.println("上传成功");} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}
/* 在后台代码中,定义三个变量,并给出set方法,struts会自动往属性里注入值
1. private File resoursefile(和你在jsp页面input file标签里的name属性值相同)---->临时文件
2.private String <span style="font-family: Arial, Helvetica, sans-serif;">resourcefileFileName ------>上传的文件名</span>
<span style="font-family:Arial, Helvetica, sans-serif;">3.private String </span><span style="font-family: Arial, Helvetica, sans-serif;">resourcefileContentType ------->上传文件的类型</span><span style="font-family:Arial, Helvetica, sans-serif;"></span>*/
0 0
- [Struts2]Struts2的文件上传
- Struts2的文件上传
- Struts2的文件上传
- Struts2的文件上传
- struts2的文件上传
- Struts2 的文件上传
- struts2的文件上传
- Struts2文件的上传
- Struts2文件的上传
- Struts2的上传
- struts2的文件上传
- Struts2文件的上传
- struts2的文件上传
- Struts2的文件上传
- struts2文件的上传
- struts2的上传例子
- Struts2的文件上传
- struts2 的文件上传
- HDU_5198
- 解决PowerDesigner 16 Generate Datebase For Sql2005/2008 对象名sysproperties无效的问题
- hdu 5225 Tom and permutation(组合数学)
- [android] intent实例
- HTML5移动应用开发为什么需要引入前端工程化
- Struts2的上传
- NTFS文件系统数据恢复----解析MFT表
- 内存池的实现
- 删除链表中的重复节点、剩余节点逆序输出
- AIDL 使用方法介绍
- dos、plsql命令窗口中执行imp/exp语句
- SQL那些事儿(二)
- jqGrid 详细API
- JS打开新窗口的2种方式