• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP and utf-8

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to display unicode characters within a JSP.
It works fine if I set the contentType in the @page directive to "text/html;charset=utf-8". However, if I include another JSP from within the first, the unicode characters from the second JSP show up as garbage.
I can get around this by also setting the contentType within the 2nd JSP to utf-8. However, the JSP specification says that only one @page attribute can be specified per JSP translation unit. So what I am doing is a violation, and I am surprised that it even works.
I am using Visual Age for Java 3.5.3, which uses JSP 1.1. Any thoughts on what the problem may be?
Erick
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you including the other JSP? If it's with an include directive (ie, @include), then that is the same translation unit. If it's with the include action (ie, jsp:include), then it ends up being a separate translation unit.
I see no notes anywhere on what happens if an included JSP file via a standard action declares a separate content type. Perhaps because it was encountered most recently, in your implementation it overrides the one you set in the original JSP.
Chris
 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Chris!
I am using the <jsp:include> tag. I guess I didn't realize (until now) what the meaning of translation unit was, and why the spec would not allow multiple @page attributes. Since the generated code for an included file (i.e <jsp:include> is actually another servlet there is no problem with having a duplicate @page attribute. If I change to an <%@include> tag then only one servlet is generated, and I get an error like I would expect:
"Page directive: can't have multiple occurrences of contentType"
So the end result is that I can safely set the contentType attribute in both JSPs since they are in separate translation units.
Thanks again,
Erick
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic