jsp页面:
$.ajax({
type:"get",
dataType:"jsonp",
url: http://www.cgh.com:9091/cmis-web2/cookie/setCookie.do?cookieVal=dgrr556fghjcvn56667889hkdbj,
jsonp: 'callback',
crossDomain:true,
success: function(data){
alert(data.code);
},
beforeSend:function(){
},
complete:function(data,status){
},
error:function(){
alert("system error!");
}
});
后台接收:
@Controller
@RequestMapping("cookie")
public class CookieSetController {
@RequestMapping(value = "setCookie.do")
public @ResponseBody String setCookie(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "cookieVal") String cookieVal,String callback) {
ResultModel resultModel = new ResultModel();
try {
response.addHeader("P3P", "CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
Cookie cookie = new Cookie(ComContants.CK_SESSIONID, cookieVal);
cookie.setPath("/");
response.addCookie(cookie);
resultModel.setCodeToSuccessed();
} catch (Exception e) {
e.printStackTrace();
resultModel.setCode(ResultModel.ERROR_CODE, e.getMessage());
}
return callback+"("+JsonConvert.toJSON(resultModel)+")";
}
}