This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes html-only jsp page displaying source in safari browser on a mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "html-only jsp page displaying source in safari browser on a mac" Watch "html-only jsp page displaying source in safari browser on a mac" New topic
Author

html-only jsp page displaying source in safari browser on a mac

sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
Is there anything wrong with creating a ".jsp" page that is pure html with no scripts? I have a page like this in a site I built that lies in a chain of other jsp pages that do have scripts. I made the page a jsp page because I wasn't initially sure if I would use dynamic elements on that page or not. And I didn't think this mattered.

All the jsp pages display fine on firefox/netscape/ie when viewed on a windows machine (I wouldn't expect the browser to matter since the html is generated server-side). However, when I view the site using a safari browser on a mac machine a problem occurs: the first time I hit the html-only jsp page, it displays fine. However, every time I hit this page subsequently, safari displays the page's source code. Then if I hit the "refresh" button, it displays the page properly. But if I move to another page and then go back to the problem page, safari displays code again unless I refresh. All of the other jsp pages (that actually contain jsp scripts) are fine.

I'm not sure why this would happen since the server is sending complete and valid html code to the browser. I even copied the code that safari was receiving and ran it through a markup validator. No errors.

Is there anything wrong with having a ".jsp" page with no jsp tags? Is there a certain "<%@ page ...%> declaration required? Incidentally, I tested for this problem both with and without this...

<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="contact.htm" %>

at the top of the problem jsp. The problem occurs in both cases.

I guess the next thing I should try is to change the filetyp for the problem page to ".html" and see if this solves the problem. But I would really like to know why this is happening.

Of course a bit of my problem stems from the fact that I don't own a mac so troubleshooting is more cumbersome than it should be. I guess I need to get myself a mac mini on ebay.

If you'd like to witness this problem, get on a mac and browse (using safari) to

http://insatiablestudios.com/searchResults.jsp

Then pick a shade you like and click "add to cart". Then hit the "checkout" button. This (chooseDelivery.jsp) is the problem page (but it should display correctly the first time). Click "Ship it over land". This should call up chooseDestination.jsp. Next, hit the "back" button. You should now see html code instead of the correctly rendered page. Hit "refresh" and the page appears correctly. Now hit "back" and then "checkout" again. Displays code again.

Why? Am I missing something very simple here?

I very much appreciate any insight you may have into this problem.

Thanks,

sean
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

On three different Macs I was unable to reproduce your problem. Do you know what version of Safari that this problem was witnessed upon?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
Hi,

Thanks for your reply. I'll need to check the safari version tomorrow. I don't have the mac here (as I mentioned above).

Have you ever seen safari display html code instead of rendering the page?

sean
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

No, I have not. The only time I have seen a similar problem is, sometimes, on IE when the contextType of the page is set incorrectly.
sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
I'm still waiting to find out what versions of safari yielded this problem. I expect to know this soon.

Do you recall the specifics of the incorrect contextType that caused the display problem (in ie) that you noted, and what change fixed it? I'm suspicious that this may be part of my problem as well.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Some browsers, if the content type is not set or not recognized, will resort to text/plain.

Be sure that your content type is "text/html".
sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
Content type is set to "text/html". So I guess this isn't the problem.

I finally got the safari version that brought up code on this one page only as explained above, The safari version is 2.0.3, running on mac OS 10.4.4.

Thanks,

sean
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

That's exactly my setup. So I ain't got much more...

Has this problem been observed on mutiple Macs, or just the one? Try as I might, I cannot reproduce the behavior you report on any of my three Macs.
sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
Thanks very much Bear for checking again.

Actually, I just saw the problem again earlier tonight on a completely different mac in a different home, this one running OS 10.4.3 and safari version 2.0.2.

Maybe I wasn't clear describing how to obtain the problem. The first time you hit the chooseDelivery.jsp page, it should display correctly. Then, when you hit the "back" button from the page named chooseDestination.jsp, be sure to hit the "back" button link on the page, instead of the "back" button on the browser. Otherwise, the broser will just show the cached page.

Follow these steps:

Go to this page...
http://insatiablestudios.com/shopcart.jsp?i=192
then click "checkout".
then click the "ship it over land" link (this will take you to chooseDestination.jsp)
then click the "back" button (use the link on the page)

code should now appear (on chooseDelivery.jsp).

Do you not get this problem? I'm now 2 for 2 with this problem on both macs I've tested.

Are youy aware of any reason why it would be a problem to have a jsp page with html only (no jsp tags)?

i strongly suspect that renaming the problem page as an html page (since it doesn't need to be a jsp) will solve the problem. But I'd really like to learn why this is happening first.

I really appreciate any insight you may have.

sean
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I just did this using the liveHttpHeaders plugin on FireFox and the content type was "text/plain".



The problem only seems to be happening when I request the page in such a way as to get a 304 response code (such as using the back or refresh buttons). If I type the url in directly (and make sure it's unique), the content type comes back as 'text/html'.

So the problem really has nothing to do with the Mac client. It's actually doing exactly what it's supposed to do. MSIE and FF are masking the problem by ignoring the headers and displaying the JSP as HTML (sad to see FF doing this).

It looks like you're using Resin as your JSP/Servlet container with Apache HTTPD (which I'll refer to as just "Apache") as the web server.

Here's my first stab in the dark:
Apache is configured to pass all JSP requests to Resin.
If Resin returns a 304 (not modified) header, Apache doesn't bother to read the rest of the headers.
It just sends back it's own response with it's configured mime typing.
I'm also guessing that there is no mime type set up for ".jsp" so it is sending back the default which is "text/plain".
If I'm right, the fix is to add the mime type for 'jsp' in httpd.conf.

One test you might want to try is to hit Resin directly (if you can). If it works correctly when hitting Resin as a standalone, then you know that the culprit is either the connector or Apache httpd itself.
[ February 07, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
sean divine
Greenhorn

Joined: Oct 27, 2005
Posts: 14
Thanks for your suggestions, Ben. Yes, the site uses Resin. Unfortunately, the site is hosted with a shared jvm. I don't have much control. And as far as I can tell, I don't have the ability to modify a httpd.conf file. Where is the file usually located?

And I'm not sure what you mean by "hitting resin directly". How does one do this? You mean without a browser?

I'm not especially familiar with mime typing and don't fully understand your explanation.

I appreciate your suggestions, though. Let me know if there is something else you think I should test and/or how to implement the test (as my knowledge oif mime typing and such is minimal).

I'd really like to know how to fix this problem (other than changing the page to html).

Thanks,

sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html-only jsp page displaying source in safari browser on a mac