Thanx, Craig, but something is wrong...

| 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);
|   %>

without success.
I am using Tomcat 4.0.1.
Also tried Tomcat 3.2.3 with very similar behaviour (and result).

JSP (start file): 
<%
  String contentType = "text/html;charset=windows-1250";
  response.setContentType(contentType);
%>

Auto-generated servlet (from work directory):
 response.setContentType("text/html;charset=ISO-8859-1");
 pageContext = _jspxFactory.getPageContext(this, request, response,   "", true, 8192, 
true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();

// HTML // begin [file="/pokus.jsp";from=(1,2);to=(2,0)]
out.write("\r\n");
// end
// begin [file="/pokus.jsp";from=(2,2);to=(5,0)]
                
String contentType = "text/html;charset=windows-1250";
response.setContentType(contentType);
// end
// HTML // begin [file="/pokus.jsp";from=(5,2);to=(40,0)]

Note, that in generated servlet there is method response.setContentType() called twice.
HTML output contains "?" instead of accented characters.
 
| * 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);

The same result.

I have also tried "more coplex" approach:
I duplicated all the code for setting *out* object at the beggining of JSP...

response.setContentType("text/html;charset=windows-1250");
pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, 
true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();

Without success... The output is the same.
Once the CT is set in response, it can't be changed.

I have discussed this behaviour of  Tomcat's JSP engine with a few java gurus.
Result:
Possible Tomcat bug, becose JSP specification says:
"The contentType is ISO-8859-1 " IF NOT SPECIFIED.
Could you confirm this as the highest authority (  ;-) ) ?

| * 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.

As you mentioned, this solution is not suitable for all cases.

Thanx again for your time.

GG


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to