Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation in servlet for jsp form

 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Can any one suggest how to write validation and bussiness logic in servlet for jsp form
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For more specific validation concerns, you should perhaps consider to use a validation framework, e. g. Commons Validator.
 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Nitin Bombay " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic