Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does JSP handle exceptions?  RSS feed

 
Mark McKay
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I write a JSP file and if the user tries to do a certain action, a null pointer exception is thrown. How does the JSP environment react to this? Does the entire servlet 'crash'? If the user presses back and tries something else, is their session still dead? If one user causes an exception, will this affect other users who may be accessing the same JSP page?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark McKay wrote:Let's say I write a JSP file and if the user tries to do a certain action, a null pointer exception is thrown.

Two things:

  • If there's stuff in your JSP, like Java code, that causes it to NPE, fix the JSP. There should be nothing in a JSP, include any Java code, that can cause an NPE.
  • If a user action can cause an NPE, that's a bug that needs to be fixed. Exceptions should never be expected in production code.


  • How does the JSP environment react to this?

    Unless you've done something to handle the exception, it will just propagate upward to the container which will show a very unfriendly 500 error page to the user.

    Does the entire servlet 'crash'?

    Define "crash".

    If the user presses back and tries something else, is their session still dead?

    Their session was never dead, so it can't be "still dead".

    If one user causes an exception, will this affect other users who may be accessing the same JSP page?

    No. Unless they run into the same bug that needs fixing.
     
    Mark McKay
    Greenhorn
    Posts: 27
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I should have said: would a NPE or other exception cause the JVM to lose a user's session information, or any of the other state it manages?

    I don't have any programs that are doing this at the moment - I'm just trying to get a sense of how easily one exception from one user might propagate to potentially bring down my entire website.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66142
    141
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mark McKay wrote:I should have said: would a NPE or other exception cause the JVM to lose a user's session information, or any of the other state it manages?
    No. Only the current request fails.

    I don't have any programs that are doing this at the moment - I'm just trying to get a sense of how easily one exception from one user might propagate to potentially bring down my entire website.

    Depends upon the nature of the issue, but for the most part, only the current request should be affected, especially in a well-structured web app.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!