aspose file tools*
The moose likes Servlets and the fly likes validation in servlet for jsp form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "validation in servlet for jsp form" Watch "validation in servlet for jsp form" New topic
Author

validation in servlet for jsp form

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Hi ,

Can any one suggest how to write validation and bussiness logic in servlet for jsp form
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Hi Nitin, Welcome to javaranch.

You can view this tutorial for help but I'm giving you a very simple example where a servlet will validate if a username is ankit and password is garg





SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688


Hi Nitin,

If you want to suggestion for business logic then use same way as Ankit Garg says.

But make another POJO Class for your business logic.

Make object of that class and call method which contains all your business logic.

So, that is good practice for development and you are using MVC architect for development.

Then don't use HTML code in your Servlet make one separate jsp which contains basically your view part.

From the servlet make one requestdispatcher object and call forward method which pass your request to jsp and display it.



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Nitin Bombay wrote:Hi ,

Can any one suggest how to write validation and bussiness logic in servlet for jsp form


I want to validate data which are entered from form in Jsp and do validation of input data in servlet and please suggest what is pojo classes
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688


Hi,

POJO means Plain Old Java Object. Our Simple Java class which contains variable declaration and getter and setter method with no argument constructor that is our POJO class.

Generally MVC model flow like

Jsp --> Servlet -- > Servlet call your business logic which is your java class then Servlet get result from business class --> finally Servlet pass to jsp.

So servlet serve as Controller.
Java Class represent Business logic.
Jsp contains view Part.

Frank Eichfelder
Ranch Hand

Joined: Aug 25, 2003
Posts: 33
For more specific validation concerns, you should perhaps consider to use a validation framework, e. g. Commons Validator.
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Nishan Patel wrote:
Hi,

POJO means Plain Old Java Object. Our Simple Java class which contains variable declaration and getter and setter method with no argument constructor that is our POJO class.

Generally MVC model flow like

Jsp --> Servlet -- > Servlet call your business logic which is your java class then Servlet get result from business class --> finally Servlet pass to jsp.

So servlet serve as Controller.
Java Class represent Business logic.
Jsp contains view Part.

hi please suggest how to implement the validation in servlet as we do in jsp with javascript function ,if possible give example
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Nitin Bombay wrote: hi please suggest how to implement the validation in servlet as we do in jsp with javascript function


jsp is used for the view purpose . so use javascript in jsp rather than servlet .just if you want to know, already ankit mentioned above that how to display data from servlet
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Nishan Patel wrote:
Hi Nitin,

If you want to suggestion for business logic then use same way as Ankit Garg says.

But make another POJO Class for your business logic.

Make object of that class and call method which contains all your business logic.

So, that is good practice for development and you are using MVC architect for development.

Then don't use HTML code in your Servlet make one separate jsp which contains basically your view part.

From the servlet make one requestdispatcher object and call forward method which pass your request to jsp and display it.



As I said, it was a very basic example .

Coming to the question, you can't validate a whole form in javascript. Usually we validate form values for correctness using javascript like checking the length of fields etc.

And I think you must go through the tutorial that I gave which shows a complete example using the strategies that Nishan is referring to...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Bauke Scholtz wrote:You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html


Hi,

Thanks for suggestion, But i want to check validation for inserting data into database .the value need to be insert from Jsp and validation( such as allow only string ,allow only numeric value) need to be check in servlet .please suggest with example
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"Nitin Bombay " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Nitin Bombay wrote:
Bauke Scholtz wrote:You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html


Hi,

Thanks for suggestion, But i want to check validation for inserting data into database .the value need to be insert from Jsp and validation( such as allow only string ,allow only numeric value) need to be check in servlet .please suggest with example

That's already covered.
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Bauke Scholtz wrote:
Nitin Bombay wrote:
Bauke Scholtz wrote:You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html


Hi,

But here(in the tutorial) no jsp page is given ,Please suggest how to insert data from jsp form .
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Bauke Scholtz wrote:
Nitin Bombay wrote:
Bauke Scholtz wrote:You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html


Hi,

Thanks for suggestion, But i want to check validation for inserting data into database .the value need to be insert from Jsp and validation( such as allow only string ,allow only numeric value) need to be check in servlet .please suggest with example

That's already covered.



Please suggest how to insert data from jsp form .As in the tutorial no jsp page is given
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"Nitin Bombay " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Nitin Belaram wrote:
Bauke Scholtz wrote:
Nitin Bombay wrote:
Bauke Scholtz wrote:You may find this article useful to get some basic ideas out: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html


Hi,

Thanks for suggestion, But i want to check validation for inserting data into database .the value need to be insert from Jsp and validation( such as allow only string ,allow only numeric value) need to be check in servlet .please suggest with example

That's already covered.



Please suggest how to insert data from jsp form .As in the tutorial no jsp page is given



Hi any one please suggest how to insert data from jsp form via using this example(tutorial) As no jsp page is given .
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Maybe you didn't read it carefully. The JSP page is given here: http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html#UserRegistrationJSPFile

Do not scan the article, but read the article from A up to Z.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation in servlet for jsp form