Solved

JSP error Page..where is the error coming from?

Posted on 2001-06-11
15
204 Views
Last Modified: 2011-09-20
hi,
i have a JSP error page.., which is forwarded when ever there is a exception. i want to know from page this error page has been forwarded to, or in other words in which page does exception came.
0
Comment
Question by:agsingh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176270
Hi Singh
Why can't u have a session object which tells which page he is using lastly.

Shyam
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6176282
I first thought about using the Referer: but error pages aren't redirected, they are forwarded. That means, no round-trip, so no Referer, too.

Another suggestion would be to store the path of the jsp page in a session attribute. Put this at the head of every jsp page:

session.setAttribute("pageUrl", request.getServletPath());

(or use getContextPath() or another path/url getter in HttpRequest.)

Then you should be able to get the source of the error in the error page like this:

String errorFromPage = session.getAttribute("pageUrl");
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176307
Hi Elpp

Thanks for the comment. We are thinking same.
Seeing u after a long time.
Cheers
Shyam
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:kvkamesh
ID: 6176308
<%@ page language="java" import="java.util.*" errorPage="error.html"; %> this error page will display when ever you catch error in the respective page. suppose you have caught an error while login means login.jsp page, it displays error.html page. that means you have an error on login.jsp.
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176319
Hi Elpp

Thanks for the comment. We are thinking same.
Seeing u after a long time.
Cheers
Shyam
0
 

Author Comment

by:agsingh
ID: 6176784
hi ,
i think u are not getting my question, in my application i dont want the users to know about the exception, instead common page comes up for each exception. Now the need is that when a person submits this error page a mail should come to me, informing about the exception and where it has occured. by putting servlet path in all the jsp will solve this problem but iam looking for a neater solution
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6176803
You still are not very clear about your intentions. I am guessing at your intentions now.

As for sending an e-mail to you, you could add a mailto form in HTML. Like this:

<form action="mailto:your-email@your-company.com" method=post enctype="text/plain">

<!-- here put the form elements (like an input field for an error description and a hidden fields for java exceptions the jsp generated. --!>

</form>

And you still can use my solution above to put the exact location (the jsp) where the exception happened and put the info in another hidden field of the form.
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176813
Hi Singh

Once an exception has occured handle check with the error handler if it is a serious one. Then u can directly call up the Javamail to send a mail and redirect it to the error with the your own errorno to handle it.

I have a doubt Elpp can u help me. In your solution. above, when this form gets submited. Are these code present in the error page or the page which is causing this error.

If u can clear it then i too accept ur comments as a solution. Can u provide me an clue for your comments

Cheers
Shyam
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6176834
Hello Shyam

In the error page.

Here a step-by-step what happens whenever an error/exception gets thrown and not catched:

1. JSP throws exception

2. Webserver forwards to error page

3. Error page shows a mailto form which tells the user of the web application that an error happened and asks him to send an e-mail to Singh. The error page could collect additional information:

   a. The source of the exception (with the session attribute "pageUrl"
   b. The exact exception and its stack trace [with exception.printStackTrace(new PrintWriter(out));]
   c. Date and time of the exception

This additional information is put into some fields of the mailto form.

4. The user adds an error description of himself and clicks Submit

5. A mail get posted to Singh. Singh gets all information he needs in a single e-mail.
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176854
Hi Elpp
Yeah i got it. I know that, but one thing i want to make it clear.

When does this mail will be send when a error page is getting displayed or after submitting an error page by the user. I want to know this only.

Shyam
0
 
LVL 3

Accepted Solution

by:
dnoelpp earned 50 total points
ID: 6176876
Only when user submits. Yes, I understand where are you going. Imagine the user got fed up and just leaves the app without clicking on Submit. Wouldn't it be nice to be able to send an e-mail anyway? Then use JavaMail to send an e-mail anyway. Okay.

So, put an additional step between step 3 and 4: Send an e-mail to Singh which contains all information gathered (without the error description of the user, then). This way Singh gets an e-mail in any case, and when the user bothers to give additional information, even two.

I thought about using a time-out or the like, but this can get complicated, and violates the KISS principle (Keep It Simple, Stupid :-).
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6176933
Hey Elpp

Get u got me. U r right. That is what my concern is. Since most of the error page doesn't bothered to get the feedback from the users.

That is why i asked. If singh is interested in getting info from the user then ur solution is good always. Even then he needs javamail right.

Thanks for your valuable comments for answering my question. U r great.
Cheers
Shyam
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6176945
Thanks.
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6181882
Dear Singh

Please close the question (accept either Shyam's or my answer whichever you like the better).

Thanks.
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6421582
Why did you give me a low grade C?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question