2016-04-21 7 views
0

Ich habe ein Problem mit diesem einfachen Server-Seite-Methode (java/Hibernate):AJAX Antwort unterscheidet sich von Java/Hibernate zurückgegebenen String

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

} 

Wenn der Kunde hat einen AJAX-Request (ich verwende ExtJS) die Antwort ist:

pippotopolinopa0015↵ 

WARUM?

Ps sorry für mein schlechtes Englisch

Pps habe ich auch versucht, mit:

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

} 
+0

versuchen Sie eine Vorlage zu rendern? oder wollen Sie einfach die Zeichenfolge als Antwort? –

+0

Ich möchte nur die Zeichenfolge! Diese Methode ist ziemlich alt und es hat sehr gut funktioniert ... bis jetzt! –

+0

haben Sie versucht, "produce =" text/plain "zu Ihrer Annotation @RequestMapping hinzuzufügen? – VirtualTroll

Antwort

0

Ich habe auf diese Weise gelöst:

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

Oder auch:

@RequestMapping(value="/Prova2" , method=RequestMethod.POST) 
@ResponseBody public StringBuffer Prova2(
     HttpServletRequest request 
     ) throws Exception 
{ 
    return new StringBuffer("pippoPlutoTopolino"); 
} 

Aber ich verstehe nicht warum funktioniert nicht und gibt einen einfachen String zurück.

Verwandte Themen