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

How to handle exception in jsp

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
Dear sir as we know that the function which produce checked exception you most be the catch in catch exception but upto in core java i know.
well as far as jsp is concerned like see following coding
<%@ page language="java"%>
<%@ page import="java.sql.*"%>


String str1="select ename from emp where empno=?" ;
String str2=request.getParameter("text");
int n=Integer.parseInt(str2.trim());
Connection con=DriverManager.getConnection ("jdbcdbc:MyDataSource","scott","tiger");
PreparedStatement ps=con.prepareStatement(str1);
ResultSet rs=ps.executeQuery();;
String str3=rs.getString("ename");
out.println("Employee name is ");
catch(Exception e){

since above statment is not working even no error

will it work , or if i will ad a another page which is concerned with exception like with function exception.getClass() and if i will remove catch statment from this page then what happen.and if work then why.
okay finally i would like to know that what happen if i will not catch checked exception in same page and if work then why it is breking rules of core java.

with regard

Arun kumar maalik
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
above statment is not working

What does this mean? No output? Too much output? Incorrect output? Is the correct statement sent to the DB? TellTheDetails
nizams uddin

Joined: Jul 31, 2006
Posts: 15

not able to understand your question.

but think yu are talking abuot exception being thrown in jsp.
if this is thte qs, then pls check the code.
i think the str2 value might be null and you are doing a trim on str2.
pls check the value of str2 and then proceed.
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
sorry sir Actualy i would like to know that in jsp you can handle your error or exception by including another error page okay.
now see
suppose i have make a jsp in whic i am using a function which is throwing a checked exception now as by rules you most catch that checked exception like see
catch(InterruptedException e){}//You most have to do this

but on the other hand in jsp you can implement same exception by including other error page without implementing the catch clause in same page
<%@page language="java"%>
<%@ page errorPage="hhh.jsp"%>
//some code herer
%>//no catch here

and the implemention of hhh.jsp page is as

<%@ page isErrorPage="true"%>

and it will work why sir although we know that we most have to catch the checked exception but here we are not catching.

I would like to know this

with regard

Arun kumar maalik
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

nizams uddin,

We appreciate that you are trying to help and answer questions here on the Ranch, but your posts will be more effective if you use real words rather than SMS contractions like yu, pls, and qs.

Such abbreviations are not accepatable. Please read this for more information.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: How to handle exception in jsp
It's not a secret anymore!