Jess,

> How does one dynamically obtain a JspWriter using a desired character
> encoding?

According to the spec, you can only write with a Writer that has the charset you
declared in the page directive.
However - the way you said you tried it, seems to be the most promising:

Set a contenttype using setContentType(String) after the page directive. e.g.:
<@ page ...>
<%
response.setContentType("text/html;charset=UTF-8");
%>

Do this if possible as the very first thing in your page, but at least before the
specified buffer is flushed for the first time.

> My problem specifically is that I have a JSP page which can dynamically
> select XSLT stylesheets to apply to XML.  XSLT stylesheets call out their
> output MIME type *and* character encoding in one of their tags.  One then
> typically includes HTML META tags that match this or, in the case of XML
> output, XSLT will declare the character encoding in the XML header of the
> output.

Do not try the HTML META approach - it will not work as it is ignored by the
engine.

> With servlets, I simply do response.getOutputStream() and let the XSLT
> library create the correct Writer.  With JSP, I get only a JspWriter, whose
> character encoding I don't seem to have dynamic control over, i.e. I can
> declare it in a page declaration, but I can't say "give me a JSP writer with
> an encoding of myXSLT.getCharEncoding()".  How is this intended to work in
> reality?  DO NOT tell me I have to have 'n' JSP pages for all of my intended
> character encodings (I only intend one but those using this stuff will
> declare any JVM-valid character encoding in their XSLT).  Also, DO NOT tell
> me that I have to reparse my XSLT output to remove this declaration and
> dynamically replace it with that specified by JSP.
>
> Along these lines, does JSP automatically HTML/XML escape characters outside
> the bounds of the target character encoding???  For instance, if outputting
> to Latin-1 are Japanese Unicode characters automatically escaped ala &#393;?

No, they aren't.

> Also, why can't I use an OutputStream from JSP?  What if I want to
> dynamically create a GIF or a JPEG?  In other words, no, such output formats
> won't leverage JSP's template nature, but JSP could still be an attractive
> way of getting a new dynamically generated servlet which called utilities
> for such.

JSP was designed for textual data. I agree that one could produce binary data with
it - but maybe then you should rather use a Servlet, just think of all these not
wanted newlines and tabs... a nightmare!

>  I am mainly trying to understand *intent* on this matter, but I
> really *need* to understand how to synchronize character encodings between
> dynamically selected XSLT pages and the JspWriter.
>
> What I am doing now, but haven't really tested is simply setting the
> Content-Type header to match my XSLT's MIME and encoding and then using the
> JspWriter (for the first time, i.e. I don't even have blank lines before
> this) to dump the XSLT output.  I have *zero* confidence that JSP engines
> will parse this ContentType and use the encoding I really need them to use
> when creating the JspWriter.

And you are right not to have that confidence.

The above mentioned approach is logical and definitely works with some, maybe all
engines, BUT: it is not explicitly defined in the spec!

Hope this helped,

-hendrik
- - - - - - - - - - - - - - - - - - - - - - - - - - -
  tagtraum industries      http://www.tagtraum.com/
  jo!                 small&smart 2.2 servletengine
  Java Server & Servlets   The web-application book
  The WebApp Framework        http://www.webapp.de/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to