文件上传功能
1,jsp页面
<form action="materialAdd.action" method="post" enctype="multipart/form-data">
<tr>
<td>附件</td>
<td>
<input type="file" name="file" id="file"/><a style="color:red">请不要上传大于100M的文件</a>
</td>
</tr>
<td colspan="2"><input type="submit" value="提交" οnclick="return checkForm1()"/>
</form>
2,xml文件
<action name="materialAdd" class="bbsq.action.materialAction" method="addMaterial">
<result name="success" type="redirect">bbsMaterial.action</result>
<result name="suggestion" type="redirect">suggestion.action</result>
<result name="input">/teacher/bbs/addMaterialerror.jsp</result>
</action>
3,java代码
并生成get和色图方法
String realPath = rd.getProperty("realPath"); //从properties中获得realpath。
String picture="/" + new Date().getTime() + fileFileName ; //获得文件名
String picPath=realPath +picture; //生成文件的存储路径
File saveFile=new File(picPath); //按照存储路径生成文件
FileUtils.copyFile(file, saveFile); //将文件拷贝到生成的文件中去