File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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
Greenhorn

Joined: Jan 23, 2012
Posts: 28
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: 2329
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
Greenhorn

Joined: Jan 23, 2012
Posts: 28
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 opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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
Greenhorn

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

Joined: Nov 06, 2000
Posts: 1503
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 opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

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.

 
 
subject: How to send alrt message from servlet to html
 
Threads others viewed
Doubt in Servlet
How to embed a html file in a servlet ?
How make mail message using JSP?
How can I send data with a hyperlink?
How to validate HTML form using servlet
developer file tools