This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hi i have a list of brand names and image namse that i need to get from a database on the home page of my site. There is no button that will send the request. I need to send the request when the page is loading. I am a little confused on how to accomplish this.
I searched the web and found:<%request.getRequestDispatcher("dispVendors").include(request,response);%>
This calls my servlet. I have debugged it in eclipse but i am not sure how to send the arraylist back after it is filled.
1. Could I do this by creating an index.jsp page the when you go to the main URL, this page calls the servlet that then forward all the info i need to Home.jsp? or is there a better way to do this?
2. Is there a way to, in one page when it loads request data from a servlet and have it returned to the same page before it fully loads?
3. Going forward i would like to dynamicaly generate meta tags from the DB so as each page loads i would like to get that info from the DB and add it to the head of my jsp.
maybe i am just looking at this the wrong way, just looking for some direction.
Ok, I see what you mean. I know how to do it when you have an action button. But in this case its the home page. So would the best way be to create an index.jsp page that calls my servlet, then forwards it to lets say home.jsp which displays my home page with all the info i need?
If you are using a modern version of servlets, you can set up your "welcome file" to be a servlet. Or, yeah, just put an index.jsp in the root folder that redirects to the servlet URL. [ September 10, 2008: Message edited by: Bear Bibeault ]
so as far as the meta tags i can have my index.jsp call my servlet which can make a DB call to fill my array list with vendors, then get my meta tag data from the db and send both back in the response by:
I'm not quite sure what you mean by "meta tag data from the db", but yes, in order to "pass" data from the servlet to the JSP, you would create scoped variables with setAttribute() which can then be referenced on the JSP using the EL (Expression Language). Avoid any Java code on the JSP -- that's the old way of doing things.
in my jsp i cn use
Please avoid using abbreviation like "cn" for "can". Thanks. [ September 10, 2008: Message edited by: Bear Bibeault ]
Joined: Sep 10, 2008
Please avoid using abbreviation like "cn" for "can". Thanks.
sorry typo, sometimes my fingers are faster than my brain.
As far as the meta tags. What i want to do i have a table in a DB that holds all my keywords and such for the meta tag data for each vendor. then when my servlet is called and the page is forwarded i want to put the appropriate meta tags on the top of that page. [ September 10, 2008: Message edited by: John Schretz ]