sql - Keeping queries out of JSP - how? -
I am a big fan of application logic in the servlet, and keep JSP as simple as possible. One reason for this is that any good web designer should be able to create simple repetition, access cells, etc. in the creation of some JSTL tags on their HTML knowledge. We also have a more complex / AJAX / JS component behind it, a tag library (similar to displayTag, but for our own components).
Most of the time, everything works properly - servlet needs any SQL, and stores results for seeds for the use of JSP. Where we have a problem when we want to access the records, it is specified by the design.
A clear example would be the Home Page - it needs to be eye catchy and effective. It does not need to be the same as the rest of the site. There are many or one "special cases" Where we want to check a specific product record, or whatever.
What the designer really wants is a method of obtaining a product line from the product ID so that it can reach the properties in general. We do not want to query for all products explicitly, and I do not want to ask in the presentation.
I am pretty sure that I am asking impossible here and I have to give something up What is my question
Edit
Is it wrong to think that all application logic should be complete before calling JSP ? I was under the impression that this was considered to be the best practice to perform all the query / calculation / processing in the Sabette, then pass the dumb (enough) dumb beans to (very) dumb JSP.
There are some methods in which the actual complexity of the query can be explained in another category (custom tag or bean), and JSP can call it. It keeps JSP simple (goal 1), but JSP is still a "triggering" query - the process is too late.
- Is it completely wrong to me and it's okay to do this. / Li>
- Is this a general rule, but in this example it is completely okay to do this.
- Can I run into problems?
Edit - Example
I hope that this example will help:
Home page There is no "template" like category / search pages - it's custom made to work very well, says a marketing image and some specific product images, despite this there are information about the two products that have a dynamic form Should be obtained from (hence the name and important origin) I) Stay in sync with DB
The servlet does not know which products will be, because if the designer wants to add / remove them / add more, they will only suggest JSP (and potentially suggest XML as a reply). Given) has to be edited.
If I understand correctly, then you have a logic in JSP which wants a particular product. But at this point you do not want to ask DB, and it is too late for the servicelet, be aware of it.
(Note one side, while I respect my wishes so that we can keep anxieties separate, it is true that this one issue clearly shows that in the presentation level there is too much in your structure Logic is .. but since we probably can not decide ... on moving forward).
My recommendation is that your designer creates a configuration XML file, in which case it is needed in front of the frontend, and can read your servlet, then send dumb beans back to JSP.
Or ... you break things in many requests using XMLHTTPRequest and call back the servlet for each individual query, then gather the page on the client.
Comments
Post a Comment