aspose file tools*
The moose likes JSP and the fly likes not able to catch exceptions from jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "not able to catch exceptions from jsp page" Watch "not able to catch exceptions from jsp page" New topic
Author

not able to catch exceptions from jsp page

apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
I use html templates in my jsp page for displaying common portion in all my jsp pages. I am not using taglib .Once the user login I set the session Object of jsp and pass it to other jsp pages . Now the problem is that I am not able to catch exceptions from this pages (pages in which i use html templates,in pages other than having templates i am able to catch the exception)(i have defined an error page, set isErrorPage = true , i.e it is sytactically right).Is this problem due to html template or due to session Object ??? I am pretty
confused.....
please help me out........
thanx in advance,
regards,
Apurva.
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
exception catching is noting to do with html template in jsp. Give more information to help you in a better way rather then guesses to your problem.
-arun


Sharing is learning
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
Yes a bit more information would be useful.
One thought though, I always thought isErrorPage=true should be used on pages which have been redirected to because an error was thrown in another page. The error page then has hold of the Exception object and is able to handle it appropriately.
I usually have isErrorPage=false on any page which may throw an exception and define my error page using the errorPage attribute of the page directive, then when the exception is thrown you are passed to a page where isErrorPage=true and it handles the exception appropriately.
There may not be much benefit it doing it this way, it's just my preferred method. Maybe someone else does it differently.
Also in my experience of using templates make sure you define things like isErrorPage on the master template which holds all of the others.


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
mahadevan raja
Ranch Hand

Joined: Apr 11, 2001
Posts: 96
HI,
try to explain ur problem in detail,html templates have nothing to do with catching exceptions.


SPECIALIST-WCSV5.1 Implementation.<br />SYSTEMS EXPERT-WAS4.0 Administration
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
thanx every one for your reply,
I would explain it in detail....
actually i want to throw an exception of invalid Session i.e when user logout then they will be presented the logout message but if the user uses the back button & moves to the previous page from which it has loggedout & try to access that page then it must throw the exception. My code looks like this
//code 1
<%@page errorPage="sessionInvalid.jsp" %>
sessionInvalid =(String)session.getValue("sessionInvalid ");
if(sessionInvalid == "true" )
{
System.out.println("inside if of
sessionInvalid =='true')");
throw new Exception ("Invalid Session");
}
must throw the Exception.
I set the session Object in the the logout.jsp page by the foll code.
//code 2
session.putValue("sessionInvalid ","true");
now the problem is that that the session variable gets set to "true" in logout.jsp i.e code 2. Now when user tries to access the previous page the control goes into the if block of code 1, it prints the statement in System.out.println but the execution gets hang from this point
throw new Exception ("Invalid Session");
I think must have understood my problem.....
your any help will be appreciated ...
regards .....
Apurva
Napa Sreedhar
Ranch Hand

Joined: Jan 29, 2002
Posts: 62
-------
Note: error page jsp is called when there is some exception thrown from other pages.
-------
once the user logs out you are setting the sessionInvalid = true which is quite OK {logout.jsp} . But errorpage jsp is never called from logout.jsp.
Alternative 2
You may have to put your code 1 part in every jsp page if the user uses the back button & moves to the previous page.
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
thanx napa for ur reply,
actually my errorpage jsp is not called from logout.jsp but it is called from the previous page. And I have put this code 1 in every jsp pages.
your every help will be appreciated .....
regards ....
Apurva
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi one more approch to solve your problem is add this line of code in every jsp. Which will not allow user to use browser back button, by not keeping the pages in cache.
<%
response.setHeader("Expires","0");
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
%>
This may help you
-arun
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
hi arun,
I tried this code but didnt work , I think it doesnt work with IE5 so thats the problem ....
I use IE5 & Inprise Application server.
so any solutions ???
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
hi arun,
I tried this code but didnt work , I think it doesnt work with IE5 so thats the problem ....
I use IE5 & Inprise Application server.
so any other solutions ???
regards,
Apurva.
shai koren
Ranch Hand

Joined: Nov 04, 2001
Posts: 48
apurva ,
I used the approach of storing some user details ( from String Id to the user object itself )in the session and then in every page check that for that object in the session. if the user not logged in there is no need in throwing exception you could just send the user again to your login.jsp or any jsp that suggest to the user to login.
try having a jsp file SessionCheck.jsp
<%
String userId = (String) session.getAttribute("userid");
if( (userId == null) ||( userId.length() < 1) ) {
response.sendRedirect( <your_login_jsp> ;
return;
}
%>
and then in every jsp page :
<%@ include file="SessionCheck.jsp"%>
mind you , the methods
putValue(String name, Object value)
and
getValue(String name)
have been deprecated you should use setAttribute(String name , Object value)
or getAttribute(Strign name).
cheers
shai


Shai koren<br />SCJP2 <br />SCEA (well yea only part 1 so far)
shai koren
Ranch Hand

Joined: Nov 04, 2001
Posts: 48
sorry for that smily it meant to be
)
...
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
hi shai,
I really liked your approach,I will try to implement it ......
thanx man....
regards,
Apurva
[ February 04, 2002: Message edited by: apurva mehta ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: not able to catch exceptions from jsp page