Hello. Here's the code I am basically trying to run in a JSP page:
I can put the exception directly to the page (see the commented line), and I was also able to create an error page. While those "worked", both are extremely ugly / user unfriendly.
Can anyone give me some way I could create a nice pop-up here which can give the user some insight into why the pattern they entered was bad?
Firstly, what you are trying to do is simply impossible. Read this JspFaq entry to find out why.
Secondly, using scriptlets in a JSP has been obsolete and discredited for over 10 years now. Read this JspFaq entry.
Couldn't agree with you more here. *sigh* This is what happens when a grizzled, back-end Java developer (previously C++, more recently even C#) programmer is "assigned" to do a GUI because he's a "senior" guy. Well, I've told them I am not fluent at all in modern web pages, but of course they think it "should be easy" and ask me "then what *IS* your skillset?" Ugh. So I am trapped trying to find solutions and management doesn't feel the need to give me the time to determine the right way to do things. I know... beating a dead horse.
Of course even if I use a bean (the code snippet I showed was actually abstracted out of a bean call so I wouldn't have more code than necessary), at the end of the day I will have to provide the user with a message... and I'm not sure of the best way even if the bean does ALL the processing.
Thank you for the links... I will see what I can do here.
Sorry to hear of your predicament. But we're here to help.
What is the end goal? It's really not a good idea to show exceptions to end users. They have no idea what they are looking at.
You'd be better of dealing with the exception in code, logging it so that developers can see it and determine what went wrong, and then showing a generic "Oops, the server went belly up" message to the end user.
And of course, none of this should be done in a JSP. Are you writing new code, or saddled with badly written legacy pages?
Joined: Mar 05, 2009
Fortunately it is new code. If they'd gotten a web developer (my company has MANY of them), I'm sure this would have been a breeze.
You are exactly right: logging the real problems and then simply responding to the user with "something went wrong... please try again" is the best bet. I wasn't trying to give them a stack trace (that would have been super easy but also NOT DESIRABLE on so many levels. I keep forgetting (since my typical work doesn't involve end users, usually other systems) that my user community isn't programmers by trade; I simply saw what would have lead me DIRECTLY to the problem and thought I should send it along. I think I can make a decent message on the error page if I simply don't try to send the included exception message.
Thanks so much for your time!
subject: Trying to use a PatternSyntaxException message for a pop-up in a JSP page