File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Feeling like an idiot with XMLHttpRequest - Servlet talking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Feeling like an idiot with XMLHttpRequest - Servlet talking" Watch "Feeling like an idiot with XMLHttpRequest - Servlet talking" New topic
Author

Feeling like an idiot with XMLHttpRequest - Servlet talking

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Well I must preface this by saying Im feeling like a first day programmer here ... like an idiot for even to have to ask this question but I am stumped!

Im spending the day learning XMLHttpRequest and have seen mutliple posts and articles around saying the XMLHttpRequest object simply calls a servlet, grabs the data and displays it... seemed simple but Im stuck wondering HOW the Servlet returns the data! Ive been thru the servlet API 3 times looking for something, some method of the Response object that allows me to send the data back and either Im completely missing something here or there is some layer, some piece of the puzzle I am missing...

Can someone kick me in the head hear and send me down the right path!

Thanks in advance!
Bryan Hughes
Greenhorn

Joined: Feb 16, 2004
Posts: 10
I'm working on this as well. I've got a working example at work. I'll reply to this message tomorrow when I get a moment to review it.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Thanks, Id actually like to see it ...... I was able to get the data back (im pulling data from a db) by using PrintWriter but MAN that seems weird sending it back that way! Maybe Im making too much of it but it just doesnt seem like the right way to do it!

Thanks Again!
H Wilson
Ranch Hand

Joined: Feb 23, 2005
Posts: 33
Originally posted by DC Dalton:
Thanks, Id actually like to see it ...... I was able to get the data back (im pulling data from a db) by using PrintWriter but MAN that seems weird sending it back that way! Maybe Im making too much of it but it just doesnt seem like the right way to do it!

Thanks Again!


You can also redirect or forward to a jsp. You can actually forward or redirect to just about any url, but I'm guessing that since you have data to display, you might want to store the data in a bean and display it in a jsp that has access to that bean. Check out the javadocs on javax.servlet.RequestDispatcher for the forward() method and javax.servlet.http.ServletResponse for the sendRedirect() method. I think Marty Hall's book "Core Java Servlets and Java ServerPages" may contain a good explanation of these methods (can't remember offhand as I read it some time ago) and I'm sure that "Head First Servlets and JSP" does. You want to call one of these methods at the end of your doGet() or doPost().
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
not looking to do that at all ..... Im just sending the data back to the calling XMLHttpRequest object, which I was able to do with a simple out.print

thanks
Juan Smith
Greenhorn

Joined: Nov 05, 2002
Posts: 1
I wrote this little app that talks to a servlet and the servlet talks to the google java API to do a background search. I think it's exactly the kind of example you are looking for - The source code is available:

http://www.josesandoval.com/2005/03/running-xmlhttprequest-with-java.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Feeling like an idiot with XMLHttpRequest - Servlet talking
 
Similar Threads
Design problem web, application
NX:Locking - one data instance or multiple
Connect, send & recieve data from remote php app inside servlet
calling a servlet from a javascript
sending xml to servlet