File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Tomcat madness! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat madness!" Watch "Tomcat madness!" New topic

Tomcat madness!

Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi folks,

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!

The first is the new one:

And here is the second:

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Moved to the Tomcat forum.

[Asking smart questions] [About Bear] [Books by Bear]
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
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.
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
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?
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Here's my 2p on it (earned, I might note, through several *painful* weeks of converting a silly webapp to support Eastern languages...).

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

Good luck
I agree. Here's the link:
subject: Tomcat madness!
It's not a secret anymore!