Thinking a lot. Gaining a lot.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
If you want something you never had do something which you had never done
Thinking a lot. Gaining a lot.
RaviNada Kiran wrote:
throw the NullPointerException and use the
<error-page> tags in web.xml file .
Thinking a lot. Gaining a lot.
Bauke Scholtz wrote:The problem is that you wrote raw Java code in a JSP file.
The JSP file itself already has initiated and committed the HTTP response.
When an exception occurs after that, the exception handler cannot change the response anymore.
Thumb rule: write Java code in Java classes and use JSP for presentation logic only. The EL and decent taglibs are capable of alternative handling when an object turns out to be null (e.g. displaying nothing and so on).
Thinking a lot. Gaining a lot.
First of all: you should not catch RuntimeExceptions unless you're really knowing what you're doing. A RuntimeException is in almost all cases caused by a developer fault. You should just write the code so that a RuntimeException would never occur. Exceptions and Errors are another story.Eric Jiang wrote:May I ask if this kind of exception(runtimeException) can be catched by servlet? Is there a method available to handle this case?
You're using Struts. There is in fact no means of a servlet. Also Struts goes beyond my knowledge. Look/google around using the keywords "struts exception handling" or so.
When I run my program. The exception displayed in the page directly. I just want to let servlet catch the exception so it will not display in the front of user. Any suggestions will be appreciated.
Bauke Scholtz wrote:The problem is that you wrote raw Java code in a JSP file.
The JSP file itself already has initiated and committed the HTTP response.
Thinking a lot. Gaining a lot.
Bauke Scholtz wrote:You talk about a servlet everytime. What servlet is it?
Thinking a lot. Gaining a lot.
Thinking a lot. Gaining a lot.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |