Posted on 2003-11-17
In regards to a previously answered question and a previous answer
>>ok, I have a jsp called ItemDetails.jsp and a servlet called ItemDetailsServlet, what i want is when the jsp is loaded
>>into a browser I want the servlet to perform a jdbc query and return the data to be displayed to the jsp, but i have
>>absolutely no idea how to do this!
>>Any help appreciated greatly!
>Either I have mis-understood this question, or you mis-understandtand what JSP's and Servlets are and do.
>A JSP is never really "loaded into the browser" - it is executed on the server and generates HTML output - that's what >is loaded into the browser.
>I think that what you really want is JSP to perform the data lookup and generate the results. If you already have Servlet >that does this, then you can call the servlet from within the JSP - or, if you have access the the source (or can
>decompile it) - you can write the functional Java into your JSP.
>Use the RequestDispatcher interface to call ("dispatch") from a JSP to a servlet.
>Get a RequestDispatcher by calling the getRequestDispatcher(java.lang.String path) method of ServletRequest
In regards to the last part of this answer I am slightly confused as to which order they should be called
does "dispatch()" take the results of a servlet to a JSP OR does it take the results from a JSP to a servlet?
is getRequestDispatcher(String path) again called from a JSP to a servlet or vice versa?
The exact nature of this problem is that we are creating a eBay type application and have a search JSP which takes in the query, the servlet is then used to query the database for the item, and then we need to send the results to the item details JSP in order to display it, the main problem is that I am unsure of how to "wrap up" the results and return it to the item details page...
so to clarify....is this feasible to use the RequestDispatcher to handle this or am i on the wrong track?