I have a html page that has a drop down menu and a submit button. Once the item in the drop down is chosen and the submit button is clicked then the html page requests some information from the servlet (which accesses a database) and then it is supposed to send/display it to a jsp. I am unsure of how to send the information that is access by the servlet, to the jsp page. I have this block of code that I know must be included in order to forward the request.
The problem is that I have rows of data to send back to the jsp and I am unsure of how to do it. Thank you in advance!! [ March 13, 2006: Message edited by: Jeanne Pierre ]
Probably you can follow the ValueObject pattern. In which, create a javabean with all of the properties you need. In the servlet, traverse through the resultset and for each row, create an instance of that javabean value object class duly filled by the values you get for that row. Add such javabean instance in an arraylist object. After the traversing is done, put that object as an attribute in request object and then do the forward to the JSP. In the JSP, simple write the logic of traversing that ArrayList object to show the values for each row.
I hope this helps. I've tried to explain in detail but if you need an example on this, let me know.
Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Ok.... sorry I think I will need an example...I was trying to do a google search of how value object works but I was not very lucky. If you could give me an example of point me to a web site that has a detailed explanation and an example I would greatly appreciate it. Thank you
Originally posted by Jeanne Pierre: Would this be legal in the servlet?
Depends what you mean by "legal".
If you mean "best practice", then no. Anytime you import java.sql.* into a servlet, you can be sure that you are violating "separation of concerns". Database code has no place anywhere in the presentation tier.
Initially it is okay, while you are learning servlets/JSPs. Once you get the code working, refactor all your database calls to a DataAccesObject (google for DAO pattern) and move your Database connection code a another utility class called ConnectionManager. The xxxxDAO class will make use of this ConnectionManager class to get a connection and your servlet will use the xxxxDAO class to map relational data to objects (i.e value object) and return the value object to your servlet.
This is so cool....I thought I got the concept of what you were saying. For some reason I don't think the list contains anything. I am just not getting what I expect. I am trying to display one of the object to the screen but I get "cannot resolve symbol" errors. I don't even know if it the servlet that is not sending the information, and I'm pretty sure that my error occurs in the way I am accessing/handeling the objects/methods.