最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JSP使用ajaxFileUpload.js實現(xiàn)跨域問題

 更新時間:2016年04月15日 12:03:22   投稿:mrr  
這篇文章主要介紹了JSP使用ajaxFileUpload.js實現(xiàn)跨域問題的相關(guān)內(nèi)容,本文介紹非常詳細,具有參考借鑒價值,感興趣的朋友一起學習吧

廢話不多說了,直接給大家貼代碼了。

jsp代碼如下

$.ajaxFileUpload 
( 
{ 
url:'http://lh.abc.com:8080/gap/gap/fileUpload.do',//用于文件上傳的服務器端請求地址(本機為fxb.abc.com) 
secureuri:false,//一般設置為false 
fileElementId:'file',//文件上傳空間的id屬性 <input type="file" id="file" name="file" /> 
dataType: 'jsonp',//返回值類型 一般設置為json 
jsonp: 'jsoncallback', 
jsonpCallback:'success_jsonpCallback', 
function success_jsonpCallback(data) { 
alert("1"); 
}, 
success: function (data, status) //服務器成功響應處理函數(shù) 
{ 
alert(data.message);//從服務器返回的json中取出message中的數(shù)據(jù),其中message為在struts2中action中定義的成員變量 
if(typeof(data.error) != 'undefined') 
{ 
if(data.error != '') 
{ 
alert(data.error); 
}else 
{ 
alert(data.message); 
} 
} 
}, 
error: function (data, status, e)//服務器響應失敗處理函數(shù) 
{ 
alert(status); 
alert(e); 
} 
} 
)

配置文件

<action name="fileUpload" class="com.gap.action.FileUploadAction" method="fileUpload">
<result type="json" name="success">
<param name="contentType">
text/html
</param>
</result>
<result type="json" name="error">
<param name="contentType">
text/html
</param>
</result>
</action>

action中的處理如下

public String fileUpload() throws Exception {
String path = ServletActionContext.getRequest().getRealPath("/upload1");
// String path = ConfigDataInfo.getConfigValue("imgServer");
try {
File f = this.getFile();
if (this.getFileFileName().endsWith(".exe")) {
message = "對不起,你上傳的文件格式不允許!!!";
} else {
FileInputStream inputStream = new FileInputStream(f);
FileOutputStream outputStream = new FileOutputStream(path + "/"
+ this.getFileFileName());
byte[] buf = new byte[1024];
int length = 0;
while ((length = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, length);
}
inputStream.close();
outputStream.flush();
message = "上傳成功";
}
} catch (Exception e) {
e.printStackTrace();
message = "對不起,文件上傳失敗了!!!!";
}
return SUCCESS;
}

每次跨域上傳圖片時,可以成功上傳到服務器上,但是不能正確的返回信息,總是進入error方法中,正確應該進入success方法

相關(guān)文章

最新評論

沙洋县| 澎湖县| 旌德县| 江孜县| 云安县| 潜江市| 翼城县| 闽清县| 锡林浩特市| 高邑县| 柳林县| 鹤岗市| 靖安县| 宾阳县| 讷河市| 磐石市| 武冈市| 崇文区| 张家川| 吴旗县| 东莞市| 长丰县| 南和县| 普定县| 西峡县| 洛隆县| 集贤县| 中阳县| 昌吉市| 姜堰市| 玛纳斯县| 麻江县| 安图县| 宁明县| 灵寿县| 宣威市| 灵石县| 吕梁市| 玉田县| 高阳县| 屯昌县|