aspose file tools*
The moose likes JSP and the fly likes How to show error messages during validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to show error messages during validation" Watch "How to show error messages during validation" New topic
Author

How to show error messages during validation

Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
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?


Raghavan
SCJP 6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
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

Joined: Jan 10, 2002
Posts: 61437
    
  67

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

Joined: Dec 20, 2005
Posts: 77

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

Joined: Jan 10, 2002
Posts: 61437
    
  67

The same way you create the session-scoped variable except that you use the setAttribute() method of HttpServletRequest.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to show error messages during validation