• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Call servlet class from jsp?

 
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

the jsp

 
Saloon Keeper
Posts: 6712
161
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SeanMichael Hayes wrote: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.


You'd do that by using a backing bean in the JSP. A servlet provides an interface for HTTP calls, but if the call is handled by the JSP, then there's no point in using a servlet.

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.
 
Sean Michael Hayes
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is jQuery "not working"? All you've described as far as problems go is ending up with malformed HTML, and now you've said that that's no longer a problem.

So what is the problem?
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 343
Mac OS X Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic