Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Question: Why do I see JSP code in my browser, not HTML page which supposed to b

JavaFAQ Home » Java Tools Go to all tips in Java Tools


Bookmark and Share

Why do I see JSP code in my browser, not HTML page which supposed to be generated by Tomcat?

Question: Why do I see JSP code in my browser, not HTML page which supposed to be generated by Tomcat?

I thought that I found the reason when I noticed that it was caused by trim() on null value String. But today I get it again and see that I do not use any trim().

Is it a bug in Tomcat Server? I think it is very serious problem since it exposes the original code to every visitor and if code written bad it can cause serious security problem...

Answer: From my experience it is not caused by trim() function, although as it was right mentioned in the question, it happens in case if String has null value. Actually it happens due NullPointerException, which Tomcat should catch and throw error description into browser's window and log files if such were configured.

It simply does not occur and Tomcat instead of code execution, displays it as a message (looks like long line without line breaks and white spaces...). If people were writing code perfectly and always used try-catch this should never occur Smile.

So, for example instead of:

String myString = getItfromSomewhere().trim();

wrap this line into try-catch construction:

try {
    String myString = getItfromSomewhere().trim();
} catch (Exception e) {
    // we do nothing here, since it was no error, just check
}

The answer looks simple and basic, but it is not.

We used to get good helpful error descriptions from JVM and often do not think what and how we program. First write code without thinking a second even, then compile and if is an error and explanation there, fix it. But if an error there but no explanation, we got lost Sad

Moral of this tip - do not rely on compilers, JVM, Tomcat, your PC and especially PC of your wife:-)

Try to think about what you write, program flow. If you get strange errors like this, try to find simplest reason why it is occurred, do not blame your Tomcat server and try to look at a code which you have written latest minutes, when perfect code become buggy. Most of reasons are very simple and does not lay beyond your first Java course.


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy