AJAX 响应不同于 java/hibernate 返回的字符串
AJAX response is different from java/hibernate returned string
这个简单的服务器端方法有一些问题 (java/hibernate):
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ResponseEntity<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
return new ResponseEntity<String>("pippotopolinopaperino",HttpStatus.OK);
}
如果客户端发出 AJAX 请求(我使用 ExtJs),响应为:
pippotopolinopa0015↵
为什么?
P.s对不起我的英语不好
P.p.s 我也尝试过:
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody String Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
return "pippotopolinopaperino";
}
我是这样解决的:
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody List<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
List<String> ret = new ArrayList<String>();
ret.add("pippoPlutoTopolino");
return ret;
}
或者:
@RequestMapping(value="/Prova2" , method=RequestMethod.POST)
@ResponseBody public StringBuffer Prova2(
HttpServletRequest request
) throws Exception
{
return new StringBuffer("pippoPlutoTopolino");
}
但我不明白为什么不能返回一个简单的字符串。
这个简单的服务器端方法有一些问题 (java/hibernate):
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ResponseEntity<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
return new ResponseEntity<String>("pippotopolinopaperino",HttpStatus.OK);
}
如果客户端发出 AJAX 请求(我使用 ExtJs),响应为:
pippotopolinopa0015↵
为什么?
P.s对不起我的英语不好
P.p.s 我也尝试过:
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody String Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
return "pippotopolinopaperino";
}
我是这样解决的:
@RequestMapping(value="/Prova" , method=RequestMethod.POST)
@Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public @ResponseBody List<String> Prova(
HttpServletRequest request, HttpServletResponse response
) throws Exception
{
log.error("Sono qui");
List<String> ret = new ArrayList<String>();
ret.add("pippoPlutoTopolino");
return ret;
}
或者:
@RequestMapping(value="/Prova2" , method=RequestMethod.POST)
@ResponseBody public StringBuffer Prova2(
HttpServletRequest request
) throws Exception
{
return new StringBuffer("pippoPlutoTopolino");
}
但我不明白为什么不能返回一个简单的字符串。