Re: RE2: Jsp compile option for Big5 encoding / encoding question
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. 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. In JSP 1.1 you cannot reliably do this. In JSP 1.2, the container is required to allow you to set the content type and character encoding dynamically, either like this: % String contentType = text/html;charset=Big5; // Or whatever response.setContentType(contentType); % or by having a custom tag do this for you. The only restriction is that you have to set this before the output buffer is flushed. GG Craig -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: RE2: Jsp compile option for Big5 encoding / encoding question
hi Gabriel, i was having a similar proble a few months ago with big5 characters now it works properly and perfectly. first of all, my experience is that it depends on OS's default charset. my configuration is like this: at the top of the page i set charset with: %@ page contentType=text/html; charset=Big5% and also a the header part of the html code i have this: meta http-equiv=Content-Type content=text/html; charset=big5 these two together sets the charset correctly, one for the dynamic characters, and the other for the static html characters. hope this helps cheers :) - Original Message - From: Ing. Gabriel Gajdos [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, December 04, 2001 4:02 PM Subject: RE: RE2: Jsp compile option for Big5 encoding / encoding question Thanx Craig, but I affraid, this was not the problem. | | JSP (start file): | % |String contentType = text/html;charset=windows-1250; |response.setContentType(contentType); | % | | | The setting windows-1250 is not a valid character encoding name in Java. | Try Big5 instead for Traditional Chinese. Valid character encoding | names are listed in the Internationalization documentation of the JDK: | | http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html | | Craig windows-1250 IS WORKING : I mean, in servlets and in JSP too (when set as %@ %). The above mentioned code does NOT change the Content Type correctly to ANY encoding. Anyway, I tried to change my encoding to Cp1250 which is listed in sun's encoding.doc.html. BTW, windows-1250 is Windows Eastern European, not Chinese, but this is not important at the moment... ;-) Cp1250 causes the same wrong result. Anyway, I also tried (just for fun) to change the Content Type to text/html;charset=Big5. The result is the same, without any chinese signs... So what will be the next try? :-)) Thanx again. Gabriel -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: RE2: Jsp compile option for Big5 encoding / encoding question
Thanx Craig, but I affraid, this was not the problem. | | JSP (start file): | % |String contentType = text/html;charset=windows-1250; |response.setContentType(contentType); | % | | | The setting windows-1250 is not a valid character encoding name in Java. | Try Big5 instead for Traditional Chinese. Valid character encoding | names are listed in the Internationalization documentation of the JDK: | | http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html | | Craig windows-1250 IS WORKING : I mean, in servlets and in JSP too (when set as %@ %). The above mentioned code does NOT change the Content Type correctly to ANY encoding. Anyway, I tried to change my encoding to Cp1250 which is listed in sun's encoding.doc.html. BTW, windows-1250 is Windows Eastern European, not Chinese, but this is not important at the moment... ;-) Cp1250 causes the same wrong result. Anyway, I also tried (just for fun) to change the Content Type to text/html;charset=Big5. The result is the same, without any chinese signs... So what will be the next try? :-)) Thanx again. Gabriel -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: RE2: Jsp compile option for Big5 encoding / encoding question
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=x; // 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=x; // 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]
RE: RE2: Jsp compile option for Big5 encoding / encoding question
On Mon, 3 Dec 2001, Ing. Gabriel Gajdos wrote: Date: Mon, 3 Dec 2001 11:02:50 +0100 From: Ing. Gabriel Gajdos [EMAIL PROTECTED] Reply-To: Tomcat Users List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: RE: RE2: Jsp compile option for Big5 encoding / encoding question 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=x; // 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); % The setting windows-1250 is not a valid character encoding name in Java. Try Big5 instead for Traditional Chinese. Valid character encoding names are listed in the Internationalization documentation of the JDK: http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html Craig -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]