I'm a little unclear as to the concept of using jsp's and servlets. I was asked to develop something that would allow users to update/search a database. So the basic idea is that users will go to a web page, and from there be able to access the database. The information that I've read has talked about JSPs and servlets, but independently of each other. Can I use a JSP to create the web page, that calls the servlet to do the db connection? Is this how it works? Annette
Sure, if you want. JSPs are best for pages with lots of static HTML and small amounts of variable content. Servlets are best for pages with lots of variable content and small amounts of static HTML. Depending on how complex the "results" page is you may prefer to use JSP, a servlet which uses a template system such as WebMacro, or a servlet with hard-coded HTML.
Basically the JSP will just need to pass variables back to the servlet to specify the search criteria. The users will be able to navigate to different pages depending on what they want to see, and then from there enter a word by which they would like to search the database. So this would be the best way to go about doing it? Annette
The way I have been doing it is to have each dynamic request initially handled by a servlet. The servlet can
verify the user is logged on
retrieve request parameters
perform necessary actions such as database updates or queries
save results (including database result sets or other objects) into the response attributes
redirect to the proper .jsp page
If the application logic is trivial (a simple database query) I do it right in the servlet. Otherwise, I have application specific classes that handle the database interactions and business logic. This allows separating the flow of control, the business logic, and the presentation from each other. Any feedback on this approach would be appreciated.