• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input validation  RSS feed

 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code I have for input validation is shown below. But what I want is for my JSP to able to forward the result to another JSP if the user entered the data correctly. Currently the form action loops to itself. see code below.
Note: I dont want to rely on a bean.

validate_jstl.jsp


[ October 28, 2007: Message edited by: Chunnard Singh II ]

[ October 28, 2007: Message edited by: Chunnard Singh II ]
[ October 28, 2007: Message edited by: Chunnard Singh II ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should consider using Struts
 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
You should consider using Struts


But that would get me back to using a bean.
 
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
Originally posted by Michael Ku:
You should consider using Struts

Sugesting using a framework or other tool without explaning how it would help the issue is usually not very helpful.

Chunnard, in an old-fashioned Model 1 patterned application (where JSPs submit to themselves or other JSPs), you are pretty much stuck with either putting scriplets on pages to perform server-side actions, or to factor such code out into beans.

The fact that you are using JSTL indicates that you want to use modern tools. But doing so in old-fashioned patterns (like Model 1) can be problematic or limiting. The JSTL can be used for minimal operations, like very simple validation, but that's not its primary purpose. Modern JSP and the JSTL is best suited for use in best-practice patterns like Model 2.

Perhaps this article might be helpful.
[ October 28, 2007: Message edited by: Bear Bibeault ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you used Struts then, in your action, you could control to where you navigate. If your validation was passed, you could go to one page. If your validation failed, you could navigate to another page. The validation could be handled by either the Struts validation framework or manually in your action.

Would you elaborate on your objection to using a bean? I do not understand the objection.
 
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
Originally posted by Michael Ku:
If you used Struts then, in your action, you could control to where you navigate.

True, but this is countered by the fact that Struts is a big and complicated framework and adopting it just to do validation, which is very easy to do without any framework assist, is a bit of overkill.

Would you elaborate on your objection to using a bean? I do not understand the objection.

I concur. If you are going to operate using a Model 1 structure, then doing things from beans in the JSPs is really the only way to go. I advise against using a Model 1 structure, but if you are going to, you really need to embrace the use of beans for processing.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not for the validation requirement that I suggested the use of Struts, it is to get away from Model1 architecture. This point seems to be well handled so I will get out of the way of the discussion.
 
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
Originally posted by Michael Ku:
It's not for the validation requirement that I suggested the use of Struts, it is to get away from Model1 architecture.

OK, that wasn't clear. I'd still not recommend Struts -- Model 2 is just as easy without a framework - but thanks for clarifying your point.

This point seems to be well handled so I will get out of the way of the discussion.

Why? Discussion is good. More viewpoints give posters the benfit of multiple opinions.
[ October 28, 2007: Message edited by: Bear Bibeault ]
 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All thanks for your responses. Sorry for getting to this late.
My question is Why isn't anyone recommending JavaScript validations?

right now The choices I have
1. simple validation with JSTL(without beans) but the drawback is that with this technique I cant check if the data is well formed for ex: cant check for '@' in email.I can only check if the parameter has isnt Null.

2. JSTL with a bean. I can check for special characters.

3. Client side Javascript where I can check for special characters and provide effects like making a red star appear next to unfilled data with information of whats missing. This looks exactly like server side validation. Isnt this a better option?(this is the reason why I liked server side validation in the first place)

The page load factor with todays broadband speeds isnt that big a factor is it?
 
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
Client-side validation is no validation at all. It can be peformed as a benefit for the user (quick report of possible errors), but server-side code must never ever ever, and did I mention NEVER, rely upon client-side validation.

Client-side code is too easy to skip, disable or spoof for your server to rely upon it.
[ October 31, 2007: Message edited by: Bear Bibeault ]
 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is there some rule as to when we can actually use javascript? You've emphasized that server side code shouldn't rely on JavaScript, so now I'm confused if I need to recheck everything using server side logic for well formed data then what is the point of javascript? Is there some rule or convention to follow? The majority would have it on and wouldn't want to do spoofing right?
 
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
Originally posted by Chunnard Singh II:
So is there some rule as to when we can actually use javascript?

You can always use JavaScript. but what you can't do is rely upon that validation. Client-side validation doesn't do anything to ensure data interity; all it does is provide a good user experience.

You've emphasized that server side code shouldn't rely on JavaScript, so now I'm confused if I need to recheck everything using server side logic for well formed data then what is the point of javascript?

See above. JavaScript validation can let your users know of errors before submission. The server can never assume that client-side validation has taken place.

Is there some rule or convention to follow?

Yes. Always validate your data on the server, regarless of whether client-side validation is employed or not.

The majority would have it on and wouldn't want to do spoofing right?

Correct, but it might only take one script kiddie to bring your site down.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!