+1; the best place to do that is in a place designed for it--servlet, action, whatever back-end technology you're using.
The idea is to separate presentation from business logic/etc.
posted 11 years ago
Thanks for the reply.
I have two cases.
1. I have some of the form elements like checkboxes, radio buttons etc in the database, cause it changes very frequently and I sometimes get
requests to add another checbox to the list.
Is it best practice to use SQL jstl to display these checkboxes in the jsp page, or should I separate out this too.
Should I put this in a servlet too?
2. I have to query the database for the results to be display and then apply access logic. If I put it in the servlet how can I pass it to the jsp page ?
1. It is never best practice to use the JSTL SQL tags. It is always best practice to never perform any database access outside the model layer.
2. All database access should take place in the model layer. Not even your servlet should have anything to do with a database. The model layer returns the result of any querying in normal, everyday Java collections or other constructs. resultsets should never rear their heads anywhere near the UI.
But one more question. Suppose I have like a huge resultset that I need to display in the JSP page.
I obtain the results in the model layer. How can I pass it to the view?
Is it good to store it in the request?
Essentially, your page controller servlet (see article) will ask the model layer for the data, and it will put it in a request scoped variable to carry to the JSP page which will be forwarded to.
With regards to size, how big are we talking here? You should never be sending sizable data sets to the JSP -- what's the user going to do when confronted with thousands of records?
Rather, give the user the ability to filter the results, and when the data set is still large, use paging techniques (also covered in the JSP FAQ) to limit the amount of data you inundate the user with.