AJAX响应不同于java / hibernate返回的字符串

时间:2016-04-21 15:39:06

标签: java ajax hibernate extjs responsetext

这个简单的服务器端方法(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.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"; 

}

1 个答案:

答案 0 :(得分:0)

我已经用这种方式解决了:

@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");  
}

但我不明白为什么不能返回一个简单的String。