File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to show error messages during validation

 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic