• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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

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
agsingh
Asked:
agsingh
1 Solution
 
shyamkumarreddyCommented:
Hi Singh
Why can't u have a session object which tells which page he is using lastly.

Shyam
0
 
dnoelppCommented:
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
 
shyamkumarreddyCommented:
Hi Elpp

Thanks for the comment. We are thinking same.
Seeing u after a long time.
Cheers
Shyam
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kvkameshCommented:
<%@ 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
 
shyamkumarreddyCommented:
Hi Elpp

Thanks for the comment. We are thinking same.
Seeing u after a long time.
Cheers
Shyam
0
 
agsinghAuthor Commented:
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
 
dnoelppCommented:
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
 
shyamkumarreddyCommented:
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
 
dnoelppCommented:
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
 
shyamkumarreddyCommented:
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
 
dnoelppCommented:
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
 
shyamkumarreddyCommented:
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
 
dnoelppCommented:
Thanks.
0
 
dnoelppCommented:
Dear Singh

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

Thanks.
0
 
dnoelppCommented:
Why did you give me a low grade C?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now