I have two JSPs that are identical in everything except their names (form1 and form1a) imaginative aren't they? I have found that Tomcat 5.0.28 generates very different servelts for the two JSPs. Not believing my eyes, I deleted the generated servlet from:
and reran the app so that the servlet would be regenerated but.... same thing!
Here are the two servelts. Don't worry about reading them. A brief scan and you will see immediately that the structure is completely different. This is not a freak occurance, I have found that when I deploy a JSP several times adding bits of code as I go, that finally this will happen. The only way out seems to be to rename the JSP and start again with a new name. This can't be right!
Excuse me if you've already considered this... But I've got a strong feeling that the pages are saved in different encoding.
Note this is *not* just what's written in the page header, e.g. : - <%@ page contentType="text/html;charset=UTF-8" ...
Rather, it's how the page is really saved on the file system. Checking for file encoding on Windows: open the file with Notepad, press "Save As", and look at the 'save' dialog that pops up: it should contain an 'encoding' field, which can be 'ANSI', "UTF-8", etc... (You don't need to actually go through with 'saving', just see the current encoding, then cancel).
I think if you test both your JSP files, Notepad would tell they have different encodings. I get this feeling because with the 2nd JSP, the first 'out.write', looks like this: - out.write("��< % @ p a g ... And the little '��' scramble at the beginning of the file is usually a 'file encoding' indicator.
Please reply if that works Good luck.
posted 13 years ago
Sol Mam Orn,
It is exactly as you said! And it never occurred to me, so thanks! One file is ANSI the other Unicode. The ANSI generates the correct servlet, so would you say I should just use ANSI in future or is it a matter of matching the charset to the file encoding? So if I want to save the jsp file as a unicode, I have to include that in pageEncoding of the page directive?
posted 13 years ago
Here's my 2p on it (earned, I might note, through several *painful* weeks of converting a silly webapp to support Eastern languages...).
1) Yep, usually (if you don't tweak Tomcat's Connector configuration), it's a matter of matching the 'physical' file format (as seen on 'save as'), with the < @%pag.. > encoding declaration... You're probably aware that when the server transmits a page to the a browser, it first sends a 'content-type' header, telling the browser which type/encoding of data to expect (watchable on IE6, through view->encoding). Now, your Tomcat usually formats that header based on the contentType/encoding declared of < %@ page ... > . If that header doensn't match the physical data, then the browser might interpret it incorrectly, usually ending up showing junk.
2) ANSI can be fine for simple english pages, but it doesn't support all foreign languages (and some special characters) - for those, use UTF-8 or unicode (but I *think* UTF taks up less space, on average).