my dog learned polymorphism*
The moose likes Servlets and the fly likes How to send alrt message from servlet to html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send alrt message from servlet to html" Watch "How to send alrt message from servlet to html" New topic
Author

How to send alrt message from servlet to html

Kasparov Patel
Ranch Hand

Joined: Jan 23, 2012
Posts: 40
Hello,

I am validating my html form in servlet. If any valye is missing or malformed my code in servlet should send alert message. Can anyone help me? How can I do?

Thanking You,
Kasparov
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
What prevents you from displaying an appropriate message in the HTML that is returned in the response? All common web frameworks (Struts, Stripes, JSF, etc.) have this functionality -displaying error messages next to input fields that failed a valiadtion- built in, by the way. You may want to check out some of those frameworks.
Kasparov Patel
Ranch Hand

Joined: Jan 23, 2012
Posts: 40
I am not getting alert message. Plese check my code given below:



This code sending back to same html page without alert message. Is there anyother way to show message beside corresponding field?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You should be using a JSP for the view so that you can make decisions about what to show or not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
M C Williams
Greenhorn

Joined: Nov 11, 2005
Posts: 4
Your servlet is generating html, so you can't just write a javascript alert statement in the html, you have to also write out a script block just as if you were writing it directly in an html file. Since you are writing the html in the servlet, you can put the notations next to each html field to mark the ones in error as you write them out into the html, and possibly an error message somewhere on the page. How you do that is a style/design choice. At that point, having an actual javascript alert may not be necessary and may be somewhat annoying to occur directly on page load. This is all assuming you are not using one of the frameworks mentioned that have this functionality built-in that you can make use of.
Kasparov Patel
Ranch Hand

Joined: Jan 23, 2012
Posts: 40
I am not familiar with framwork.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
If you are not familiar with frameworks, then Google for it and get familiar with them. It will make things much easier got you.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Bosun Bello wrote:If you are not familiar with frameworks, then Google for it and get familiar with them. It will make things much easier got you.


Meh, I'm not much of a cheer-leader for the frameworks. If the OP doesn't know enough yet to be able to send information to a JSP for conditional inclusion on the page, a framework is premature and will just add to the confusion, or, worse, actively prevent him from learning basic servlet and JSP concepts that he needs to know.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send alrt message from servlet to html
 
Similar Threads
How to embed a html file in a servlet ?
How to validate HTML form using servlet
How make mail message using JSP?
Doubt in Servlet
How can I send data with a hyperlink?