• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

validation in servlet for jsp form

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Can any one suggest how to write validation and bussiness logic in servlet for jsp form
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic