Solved

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

Posted on 2001-06-11
15
200 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
15 Comments
 
LVL 3

Expert Comment

by:shyamkumarreddy
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Elpp

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

Expert Comment

by:kvkamesh
Comment Utility
<%@ 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
Comment Utility
Hi Elpp

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

Author Comment

by:agsingh
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:shyamkumarreddy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0
 
LVL 3

Expert Comment

by:dnoelpp
Comment Utility
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
Comment Utility
Why did you give me a low grade C?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now