Solved

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

Posted on 2001-06-11
15
203 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
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
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.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 42
java stored proc example 9 44
tomcat administrtor 12 59
ejb entity bean example issue 2 16
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

840 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