• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending message to the user from a servlet

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear colleagues,

Could you please advise what you think is the best way of sending an error message from a servlet for a later presentation in a JSP page? I mean the equivalent of a JavaScript alert message.

I tried to do it by using the JOptionPane class, but I discarded as the message is shown only in the server...

Thank you all in advance.

Kind regards.

 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot mix Swing/AWT with a web app.

If you have something to show the user, you need to create it in the HTML, JavaScript and CSS for the page.

How do you want it presented? Just text on the page? A JavaScript alert (rather tacky, in my opinion)? A dialog? A modern "growl-style" notification? Other?

Once you decide how to present it, figure out the HTML, JavaScript and CSS necessary to make it happen.

Then, and only then, figure out how to use the servlet and JSP to create those constructs on the page.
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your answer.

What I'd like to show is a message coming from the servlet, for a first approach it could be valid text on the JSP page. I don't know what you mean by a modern "growl-style" notification, but it sounds good:).

I know it must be done through HTML and CSS code but this is what I want to find out. Could someone please provide a small example?

Thanks again.

Regards.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's some info on Growl: Growl_(software)

While Growl itself is for Mac OS X, its style of notifications (show in upper right corner then fade away), is very popular on the web.

There are many, many implementations for the web; most of them are jQuery plugins.

One that I've used in a few projects is Gritter, which I found easy to use (and customize).
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember, figure out how to get all this working in HTML and JavaScript first. Then, figure out how to make your servlet and JSP create the desired markup.
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Remember, figure out how to get all this working in HTML and JavaScript first. Then, figure out how to make your servlet and JSP create the desired markup.



Well, in fact this is for what I was searching some help... OK, I'll try to figure out by myself, thank you anyway...

Regarding Growl, thanks for the info, I'll try to find out more about it.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Growl is for OS X.

I said, you might want to consider a "growl style" notification system. (Such as Gritter, as I've already mentioned.)
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Likos Anthropous wrote:Well, in fact this is for what I was searching some help..


Has all this not helped?

If you decide to go with Gritter, it's one line of script to add a notification.
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Likos Anthropous wrote:Well, in fact this is for what I was searching some help..


Has all this not helped?

If you decide to go with Gritter, it's one line of script to add a notification.



Thanks Bear,

I've been tryimg to find out how to do it with Gritter. I found out some examples, but I see always the popup message is triggered after the usser press a link or a button. In my case, I want to send the message depending on the value of a session parameter, I could not find anything illustrative :). On top of this, again, I'm not familiar with jquery...

Could someone provide a short example of how to implement this with Gritter?

Thanks again.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just place the following in the ready handler when you want the message to appear on page load:
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again.

Please, how can I do to post code in the format you did?, whit that kind of indentation?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read UseCodeTags. It explains how to use the "Code" button when making replies.
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

It seems to be quite easy but I do not yet catch it completely :(

I post below the JSP code where I'm trying to use this. I must be missing something....

Thanks again for your help.



 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the problem?
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the code above the message does not appear. I want the message to be sent when the if condition is true, how can I do it please?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any scripting errors displayed on the JavaScript console?

With the statement hard-coded into the ready handler, the message should appear every time the page loads.

Did you also install the gritter images and CSS correctly?

To make it conditional, only include the statement when you want it to appear using <c:if> (rather than Java scriptlets, which you should not be using on your page.)
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
One that I've used in a few projects is Gritter, which I found easy to use (and customize).



Thumbs up for the link to Gritter. I wasn't aware of that, but I'll be using it now.
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Are there any scripting errors displayed on the JavaScript console?

With the statement hard-coded into the ready handler, the message should appear every time the page loads.

Did you also install the gritter images and CSS correctly?

To make it conditional, only include the statement when you want it to appear using <c:if> (rather than Java scriptlets, which you should not be using on your page.)



No errors on the JS console , I made sure that the css and js files are correctly located, I'm not familiar with that <c:if> you mentioned... It's OK, I don't want to take your time any longer for something that must be very easy to use.

So, thank you very much for your efforts, which I appreciate very much. Maybe I'll come back to this later on, when I'll have more time to dedicate...

Regards.

 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EL and JSTL, from which <c:if> comes, were introduced with JSP2 in 2002 to replace Java scriptlets in code. The code you posted is almost 12 years out of date! If you are serious about using JSP, you need to learn how to write modern JSP; not like people were writing it in 2001.

The JSTL and EL equivalent of your session test is simply:
 
Likos Anthropous
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your advise :)...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic