• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to catch exceptions from jsp page

 
apurva mehta
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mahadevan raja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
try to explain ur problem in detail,html templates have nothing to do with catching exceptions.
 
apurva mehta
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-------
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for that smily it meant to be
)
...
 
apurva mehta
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic