and so on, down to 20, in order to retrieve all the submitted data.
Thought of another way... 'getParameter' on the request object, is analogous to a bean's getter, but a request is NOT analogous to a bean. The request object's "getter" method has the word 'parameter' in it, and it doesn't have a corresponding 'set' method.
Joined: Jan 08, 2002
hmm... so if I have a webapp that is really just a whole load of forms for input/display of a database would it be better to use JSPs only? That way it can benefit from <jsp:setProperty> instead of the repetitve get/set methods in a servlet? - Except then there is the problem of doing SQL interaction in the jsp code - isn't it bad practise to do this sort of code in a JSP? I thought they were intended to separate business logic from presentation. I'm a bit confused as to the best approach for this, any advice much appreciated... [ April 29, 2003: Message edited by: Peter Straw ]
well the 'benefit' of the jsp:setProperty is sorta kinda covered by the 'request' object, in my opinion. The jsp mega-setter (just use * to set all the properties) is useful when the target of your form submission is another JSP page. Sort of.
The :setProperty only transfers all the params from the request into your bean. But still.. you'd have to the use :getProperty every time you wanted one of the params. Which you'd need to do for processing some sort of business transaction. Same thing in the servlet with request. So where are you saving time by using a bean in a JSP?
Well, ok... the savings is potentially here:
If you were in a servlet, you might be tempted to send an instance of HttpRequest into the business object's OrderTicket method. After all, the request contains all of our fields right? But this is a bad separation of the HTTP layer from the business layer. So what you *should* do is construct a bean that contains all the fields of interest , and pass *that* object to the method. If this were a JSP page, and not a servlet, then you'd certainly save some time by being able to use the mega-setter method.
Having said that, there's nothing stopping you from coding your own little method that does this sort of thing. After all, Sun had to code that "*" behaviour into their jsp:setProperty tag. You could too. I imagine something like:
And yah, it's a bad idea to have JDBC code in a JSP. Just google for 'model 2 servlet' and you'll find plenty of articles.