This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I'm in the middle of trying to refresh a div on my jsp using AJAX, I'm using jQuery to do this. Problem. The way my project is set up is that when it runs on a server you access the servlet first so it can create data to be sent to the jsp page so it can be accessed using jstl and displayed correctly . I'm wondering how you would go about setting it that accessing the jsp automatically calls the servlet to populate the data variables on the jsp page.
The reason I want this is because the ajax call for the servlet puts the entire html page, head and body tags and all into the div, which I believe, causes errors when I try t run the jQuery in the div. If the above is not possible, how do I go about retrieving the updated div? Google has been no help for my unique problem.
Tim Moores wrote:
It doesn't sound as if that would solve the problem of the AJAX call. For that you'd have to write a servlet that does not return a full HTML page, but just the new contents of the DIV.
he page with fireb
Ah, I just checked my servlet and and viewed the page with firebug and everything seems to be running right. No body and header tags in the div. Still doesn't solve my problem regarding the jQuery not working but its a start, thanks.
By the way, why would you not just pre-populate the page using JSP and JSTL as you originally described? Ajax should not be used for initial page loading -- just making modifications to the page as a result of events after the page has been loaded.
As far as I can partially understand the problem statement is as follows. Initially, when you want to open a page, you first hit the servlet which fetches data from db, sets it into session and redirects to a JSP where it is presented. Now, on some event you want to refresh the div on your page. Is this correct? If not, then please help me understand your problem statement.