nutz 上传文件到服务器上,仍然是原来的文件名字?
11 回复
@At("/addconfigure/?")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
public Object addconfigure( Integer cabinetid,
@Param("pic") TempFile tf,
@Param("filename") String name,
HttpServletResponse rsp, HttpServletRequest req) {
@Param("pic") TempFile tf里的
E:\apache-tomcat-7.0.82\webapps\eop\WEB-INF\tmp\00\00\00\00\00\00\00\28.jsp
@wendal 上传文件跨域名,接口怎么处理?
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="D:/jquery.js"></script>
<script src="D:/ajaxfileupload.js"></script>
<script src="D:/jquery-ui.js"></script>
<script type="text/javascript">
function ajaxFileUpload() {
var form = new FormData(document.getElementById("tf"));
$.ajaxFileUpload({
url : "http://test.xboxes.cn/eop/celltest/addconfigure/7", //用于文件上传的服务器端请求地址
secureuri : false, //是否需要安全协议,一般设置为false
fileElementId : [ "lefile", "lefile1", "lefile2","lefile3","lefile4","lefile5" ],//文件上传域的ID
data : form,
type : 'POST',
dataType : 'JSON', //返回值类型 一般设置为json
success :function(data){
//window.clearInterval(timer);
alert(3333)
} ,
error : function(e)//服务器响应失败处理函数,成功也是指向error
{
alert(data)
alert("错误!!");
}
});
}
</script>
<form id="tf" >
<input type="file" name="pic" id="lefile" value=""/>
<input type="button" onclick="ajaxFileUpload()" class="btn btn-success" value="保存"/>
</form>
@At("/addconfigure/?")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
public Object addconfigure( Integer cabinetid,
@Param("pic") TempFile tf,
HttpServletResponse rsp, HttpServletRequest req) {
if (tf != null ) {
// 要保存的图片的地址文件夹,相对于当前项目
String folder ="/upload/"+cabinetid+"/";
String targeName = saveImage(tf, req, folder);
}
Json j=new Json();
j.setStatus("0");
rsp.setHeader("Access-Control-Allow-Origin", "*");
rsp.setHeader("Access-Control-Allow-Methods",
"POST, GET, OPTIONS, DELETE");
rsp.setHeader("Access-Control-Max-Age", "3600");
rsp.setHeader("Content-Type:", " application/json");
rsp.setHeader("Access-Control-Allow-Headers",
"x-requested-with,Authorization");
rsp.setHeader("Access-Control-Allow-Credentials", "true");
//response.setContentType("application/x-www-form-urlencoded");
//((HttpServletResponse) req).setHeader("Access-Control-Allow-Origin", "*");
return j;
}
添加回复
请先登陆