HTML+JS代码:
$(function() {
$('#uploadbutton').click(
function(){
ajaxFileUpload();
}
);
});
function ajaxFileUpload() {
$.ajaxFileUpload
(
{
url: '/base/upload!doNotNeedSecurity_doupload.sy',
secure: false,
fileElementId: 'uploadphoto',
dataType: 'json',
success: function(data,status){
alert(data);
},
error: function(data,status,e){
alert(data);
}
}
);
}
<form enctype="multipart/form-data" method="post">
<table class="table" style="width: 100%;">
<tr>
<th><s:text name="message.employee.form.uploadphoto" /></th>
<td>
<input type="file" id="uploadphoto"/>
<input type="button" value="上传" id="uploadbutton"/>
</td>
</tr>
</table>
</form>
Action类:
public class UploadAction extends ActionSupport {
private static final Logger logger = Logger.getLogger(UploadAction.class);
private File uploadFile;
private String uploadFileFileName;
private String uploadFileContentType;
public File getUploadFile() {
return uploadFile;
}
public void setUploadFile(File upf){
uploadFile = upf;
}
public String getUploadFileFileName(){
return uploadFileFileName;
}
public void setUploadFileFileName(String name){
this.uploadFileFileName = name;
}
public String getUploadFileContentType(){
return uploadFileContentType;
}
public void setUploadFileContentType(String name){
this.uploadFileContentType = name;
}
public void doNotNeedSecurity_doupload(){
if(uploadFile != null){
HttpServletRequest request = ServletActionContext.getRequest();
String path = request.getRealPath("/upload");
File saveFile = new File(path, uploadFileFileName);
uploadFile.renameTo(saveFile);
Json json = new Json();
json.setSuccess(true);
json.setMsg(saveFile.getPath());
writeJson(json);
} else {
Json json = new Json();
json.setSuccess(false);
writeJson(json);
}
}
}
运行时文件传不上去。
求高手指教!
------解决思路----------------------
什么症状呢?