Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and utf-8  RSS feed

 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
 
Chris Smith
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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 is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!