On Mon, 3 Dec 2001, Ing. Gabriel Gajdos wrote:
> Date: Mon, 3 Dec 2001 09:41:39 +0100
> From: Ing. Gabriel Gajdos <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: RE2: Jsp compile option for Big5 encoding / encoding question
>
> Craig (or somebody else), could you, please, give me a hint in
> following question?
>
> | JSP pages follow these rules:
> |
> | * If you declare a "pageEncoding" attribute on your <%@ page %>
> | directive (supported in JSP 1.2 only), that character set is used
> | to read the text of the page itself (as the page is being compiled).
> |
> | * The character encoding from the contentType attribute of the
> | <%@ page %> directive is used, if present
>
> I know and use these settings...
> But:
> Is it possible to have SINGLE JSP page with *variable* encoding/Content Type?
>
> <%@ page contentType="text/html; charset=XY" %>
>
> And I want to set the Content Type (or charset/encoding) according to
> *current* conditions. For example acording to a field value from
> database, or Property from .properties file with language dependent
> settings.
>
> Is this possible in T4? IMHO JSP specifications do not say about this.
>
> I would like to make something similar (this syntax is NOT correct):
>
> <%@ page contentType="p.getProperty("ContentType")" %>
>
> I also tried a custom tag solution, but with no success. It seams,
> directives bitween <%@ %> directives can not contain executable code.
>
That is true, because directives are procesed at compile time, not at
request time.
> Of course, this approach works when using servlet (I mean variable
> ContentType). So can this also be done in JSPs? Or in this case is the
> only way to do it by using Unicode?
>
> Thanx in advance.
>
> GG
>
Yes, dynamically setting the content type and character encoding is
supported in JSP 1.2 (and therefore in Tomcat 4). You have three choices:
* You can use a scriptlet to set the content type at the top of your
JSP page:
<%
String contentType = "text/html;charset=xxxxx"; // Or whatever
response.setContentType(contentType);
%>
* You can do the equivalent to the above setting in a custom tag that is
executed before the response has been committed to the user:
String contentType = "text/html;charset=xxxxx"; // Or whatever
pageContext.getResponse().setContentType(contentType);
* You can use a Filter to set the response content type and character
set based on the characteristics of the current request. However, any
use of RequestDispatcher.forward() or <jsp:forward> will invalidate this
setting, because all headers are removed when such a forward is
processed.
Craig
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>