• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to show validation error messages on the jsp login fields from servlet  RSS feed

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have login jsp with 3 fields,userid,password and dropdown.When the jsp is submitted,the request goes to a servlet.I want to validate these 3 inputs inside the doPost() method of the servlet.Is it possible to display some error messages on the fields(userid,password,dropdown) of the jsp field if these fields are empty? Also,I want to pass these messages from the doPost() method of the servlet on the fields of the jsp.

Please give some advice as to how can I do this.


Many Thanks in advance!

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always validate these fields and then return a validation message to the user when you redirect to that page. You can achieve declarative security with form login. Not sure what you need with the drop down, so if your container can be configured to recognize that then form login should do well.

You should be able to achieve this with more ease if you use struts
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on a simple tomcat based jsp/servlet application.How can I redirect back to the jsp fields if I give null conditions in the doPost() method like:



Is this possible to implement?

Please advice

Thanks

 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this possible to implement?


Yes. You can set any messages in request scope etc.. then do a forward to the previous jsp. If you use a redirect you will have to provide those messages in the URL because browser will make a separate request for the redirect.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.Please could you provide some sample code if possible? That would be really great!!

Thanks
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved this issue by using javascript validation.

Thanks!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moieen Khatri wrote:I resolved this issue by using javascript validation.


Good. but you must learn on server side also
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moieen Khatri wrote:I resolved this issue by using javascript validation.

Thanks!


Whether you do it with javascript or not, you must always validate your parameters on the server side.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepak

I use client side validation for checking if the attributes are entered or not and I use server side validation to check if the login is successful or not.

Thanks for the advice!

Cheers
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:Whether you do it with javascript or not, you must always validate your parameters on the server side.

Quoted for emphasis.

Never rely on client-side validation. Your server-side code must act is if no client-side validation has taken place. None.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!