0

I'm using the grails framework have have the following action:

def showText () {
    def myInstace = User.get(params.id)
    def myText = myService.getText(myInstance.id)
    render (text: myText, encoding: "UTF-8", contentType: "text/plain")
}

The above works fine since when I try to see the data returned by this method uding cUrl I get something that is acceptable:

From cUrl

The (<b>quick</b>) [brown] {fox} jumps!
Over the $43,456.78 <lazy> #90 dog
& duck/goose, as 12.5% of E-mail
from aspammer@website.com is spam.
Der ,,schnelle” braune Fuchs springt
iiber den faulen Hund. Le renard brun
<<rapide» saute par-dessus le chien
v ‘$5’ paresseux. La volpe marrone rapida
“TATVPKOY ‘~35 salta sopra_1l cane pigro. El zorro

“ marron répido salta sobre el perro
perezoso. A raposa marrom rzipida
salta sobre o e50 preguicoso.

However, when this loads up on the modalbox is looks like this:

  The (quick) [brown] {fox} jumps! Over the $43,456.78 #90 dog & duck/goose, 
  as 12.5% of E-mail from aspammer@website.com is spam. Der ,,schnelle” 
  braune Fuchs springt iiber den faulen Hund. Le renard brun <

My jQuery code is simple enough:

$('a[id^="myText"]').click (function () {
   $.post($(this).data('url'), function (data){
      $("#msg").html(data);
   });
   $('#showText').modal()
});

So, I can't seem to understand what am I doing wrong? The above content is loaded into a div which gets displayed as a modal box. Additionally, my config.groovy has the UTF-8 settings:

grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
4

1 回答 1

1

You text is automatically transferred to html format, which regards <b>, <lazy>, <rapide> as html tags, and when <<rapide is rendered, there is a format error.

The solution is modify the render method in your controller with StringEscapeUtils.unescapeHtml method, as:

render (text: StringEscapeUtils.unescapeHtml(myText), encoding: "UTF-8", contentType: "text/plain")
于 2013-01-10T05:29:38.607 回答