标签:har success Enctype gets upload utils exception struts2 tco
一个小的注意点
<s:if test=‘#backyear==#yearatd‘>selected="selected"</s:if>
<s:if test=‘%{#backmonth==-1}‘>selected="selected"</s:if>
文件上传(struts2)
jsp:
<form name="myform" method="post" action="employeesAdd" enctype="multipart/form-data">
<p><span>上传头像:</span><input type="file" class="txtinput" name="upload" /></p>
Action:
//上传文件
private File upload;
//上传文件名
private String uploadFileName;
//上传文件类型
private String uploadContentType;
//....getter、setter
public String AddEmployee(){
//项目路径
String root = ServletActionContext.getServletContext().getRealPath("/");
//文件存放目录
String filepath = root+File.separatorChar+"upload";
try {
//复制文件到服务器中
FileUtils.copyFile(upload, new File(filepath,uploadFileName));
//访问文件的路径(File.separatorChar相当于"/")
String imgurl = "upload"+File.separatorChar+uploadFileName;
employee.setEpicture(imgurl);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
employeesService.addEmployee(employee);
return SUCCESS;
}
标签:har success Enctype gets upload utils exception struts2 tco
原文地址:http://www.cnblogs.com/whisper527/p/6498863.html