aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes ajax and servlet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "ajax and servlet problem" Watch "ajax and servlet problem" New topic
Author

ajax and servlet problem

nik klaus
Greenhorn

Joined: Nov 23, 2008
Posts: 8
I am trying to build a web application based on jsp ,ajax and servlets.The idea is to create a jsp that contains some options available for that user(previously he has to log in) and put a link on them.When the user clicks one of these links a xmlHttpRequest is send to the servlet informing it about this event ,the servlet performs some operations, and replys back.In the onreadystatechange I check this reply and if it is the expected one, I have to delete that link. The problem is that what ever I do ,the responseText comes back containing the html from the page that sent the request. What is it wrong ?






and the part in servlet where I respond to the request:
if (comanda.equals("register"))
{
int id=Integer.parseInt(request.getParameter("id"));
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().println("true");
}

previously I store some data in the session.
[ November 23, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Are you sure that your Ajax request is correct and causing the servlet to execute as you think it is?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nik klaus
Greenhorn

Joined: Nov 23, 2008
Posts: 8
yes ! everything woks fine until I try to use the responseText
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

At this point, I'm going to move this over to the JavaScript forum as the problem is unlikely on the server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Time to post your client-side code.
nik klaus
Greenhorn

Joined: Nov 23, 2008
Posts: 8

[ November 23, 2008: Message edited by: nik klaus ]
nik klaus
Greenhorn

Joined: Nov 23, 2008
Posts: 8
http://myfreefilehosting.com/f/e8de0128ef_2.93MB
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
One problem with your code is that the returned message might not just be true -- it's more likely to be something like \n\ntrue\n

You should use a method like indexOf on the string to see if "true" is present somewhere in the returned text (of course, this is risky, since there is some slight change that the word "true" will appear in a generated error page with a stack trace, so it's usually best to come up with something a lot more complex that is unlikely to show up in the response accidentally)

If you did something like an alert(responseText) and saw that you are getting the html code for this page, then it seems likely that you are actually just re-requesting the same page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ajax and servlet problem