aspose file tools*
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
Author

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.*"%>

<html>
<body>

<%
try{
String str1="select ename from emp where empno=?" ;
String str2=request.getParameter("text");
int n=Integer.parseInt(str2.trim());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection ("jdbcdbc:MyDataSource","scott","tiger");
PreparedStatement ps=con.prepareStatement(str1);
ps.setInt(1,n);
ResultSet rs=ps.executeQuery();
rs.next();
String str3=rs.getString("ename");
out.println("Employee name is ");
out.println(str3);
}
catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>

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
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
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


Ping & DNS - my free Android networking tools app
nizams uddin
Greenhorn

Joined: Jul 31, 2006
Posts: 15
hi,

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
try{
Thread.sleep(100)
}
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
like
<%@page language="java"%>
<%@ page errorPage="hhh.jsp"%>
<%
Thread.sleep(100)
finall{
//some code herer
}
%>//no catch here

and the implemention of hhh.jsp page is as

<%@ page isErrorPage="true"%>
<%=error.getClass()%>
<%=error.getMessage()%>

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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Arun,
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
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.

thanks,
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle exception in jsp