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. My index page (index.jsp) is supposed to be generated dynamically everytime is accessed. 1o.) Index will do some lookup into the database and retrieve information to complete the information in the web page. the connection, sql's, beans are done in a servlet. So, how do I send the request to the servlet inmediately when the page is requested? if you need more clarifications, let me know... cheers
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Hi, This is just a quick answer off the top of my head but you should be able to use a RequestDispatcher to immediately sent the request that has accessed the jsp to a servlet. I've only done this the reverse way (servlet -> jsp) but it should work the other way. Thanks, Steve
You mean more precisely: your first scriptlet in your jsp? Cause you allready use beans. And scriptlets should be avoided. You might write some custom tags or a bean to access to do the database lookups and the bean initialisation. [ April 18, 2002: Message edited by: Axel Janssen ]
U can directly call the servlet itself, why do u want to call the JSP. I mean to say, if ur servlet is IndexServlet, u can map it to "index" and ur URL would be "http://xyz.com/webapp/index" this url will invoke the servlet which dose all the JDBC connection etc.and forwards to a JSP.
Joined: Jan 13, 2002
Hi, The servlet mapping, if it works and I can't see why not, will probably be the best solution to hit the servlet directly. My only concern would be the situation where the user requests the following: www.someserver.com or www.someserver.com/ Will the webserver resolve these to /index.htm(l) and as a consequence pass the request to the servlet container as a matter of course? Also, remember that you can see the welcome page to something other than index.html in the web.xml config file Cheers, Steve [ April 19, 2002: Message edited by: Steve Granton ]
Joined: Nov 27, 2001
Hello everyone and thanks for your response. Sounds like a good idea what "mustang india" (I don't think this is your real name ) proposed, to hit the servlet directly. I'm a bit new with this situation, could you please show me a bit of code so I can get in the correct direction? Or should I just modify the web xml file and specify that the index.htm will be mapped to the servlet?? thankssss