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

How to show error messages during validation

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a registration page register.jsp and a page that processes registration information processRegister.jsp.

I find some errors in processRegister.jsp but I want to display those errors in register.jsp and how do I do that?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly I would reccomend that you never do processing in a JSP. A servlet is a much more approriate place for that kind of activity.

Secondly, during processing, you could accumulate a list of validation error messages. If any, you could attach the list to the request as a scoped variable and forward back to the original page. The logic on the page would display the list of messages if one exists. If you wanted to get fancy, you could also associate each message with a form element by name so you could highlight the fields that failed validation using a different rendering style.
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...I do not actually understand when you say process using servlets cos I am a novice...


If any, you could attach the list to the request as a scoped variable and forward back to the original page.


How do you create variables with different scope...I have heard only of bean...could you explain me???

I have used session to transport values from one page to the other....it works but I just want to make sure it is effective or you have got some better idea than what I have....

Here is my processRegistration.jsp page


[ January 02, 2006: Message edited by: Raghavan Chockalingam ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using servelts for processing and JSP for view rendition is the best accepted practice. As a novice it would do you good to familiarize yourself with this pattern at an early stage. Look up topics such as "MVC" and "Model 2" for more details.

Session is one possible scope. Request is another. For this purpose, request scope would be the most appropriate. For any scope, you use the setAttribute method of the scope to establish a variable in that scope.
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Request is another. For this purpose, request scope would be the most appropriate. For any scope, you use the setAttribute method of the scope to establish a variable in that scope.



To be honest, I still do not understand after you tried to explain me. It would be better if you can give me an example how to create a variable of request scope or you can point me to an appropriate tutorial...anyway thanks for your efforts..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same way you create the session-scoped variable except that you use the setAttribute() method of HttpServletRequest.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really ought to consider either finding a good tutorial on JSP or getting yourself a good book. These are fundamental concepts that you need to get under your belt.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic