大家好,我正在研究spring3.0 restful webservice。当我从同一服务器(即我的weblogic服务器)调用方法时,我能够调用我的方法。但是如果我想从另一台服务器使用\点击相同的方法(即我的 jboss 服务器)然后它没有达到我在 weblogic 服务器上的休息方法。
在下面的代码中,如果我在 weblogic jsp 页面中编写此代码并调用它,则返回正确的值,我可以在我的网页上显示相同的值。但是如果我将相同的代码复制到 JBOSS 服务器中的 jsp(我的不同项目访问我的休息服务)然后它没有达到我的方法。--------------------------------------
$.ajax({
url: "http://test.abc.org:7001/SpringRestService/restful/products/ALL/ALL/ALL/ALL.json",
type: "GET",
processdata: true,
dataType: "json",
contentType: "application/json;",
beforeSend: function () { },
headers :
{
"Content-Type" : "application/json",
"Accept" : "application/json",
"Access-Control-Allow-Origin":"http://its-ims002.neahq.nearoot.org:7001/"
},
success: function (data)
{
bindEvent.loadGridData(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
try
{
alert(JSON.stringify(XMLHttpRequest) + "\n" + textStatus + "\n" + errorThrown);
}
catch (ex) { alert("Exception occured.. "); }
finally { }
}
});
下面是我保存在我的 weblogic 服务器中的 java 代码,我必须使用我的 ajax 调用从 jboss 服务器中访问它。
---------------------------------
@Controller
public class HelloWorldController1 {
@RequestMapping(value = "/products/{userName}/{year}/{status}/{stateId}", method = RequestMethod.GET,consumes="application/text")
public ModelAndView getTextFromURL(@PathVariable("userName") String userName, @PathVariable("year") String year,
@PathVariable("status") String status, @PathVariable("stateId") String stateId) {
List<Abc> list= new ArrayList<Abc>();
list= service.products(userName, year, status, stateId);
ProductList productList = new ProductList (list);
ModelAndView mav = new ModelAndView();
mav.setViewName("index1");
mav.addObject("list", productList );
return mav;
}
}