aspose file tools*
The moose likes JSP and the fly likes AJAX Problem in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "AJAX Problem in JSP" Watch "AJAX Problem in JSP" New topic
Author

AJAX Problem in JSP

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Hi ,
Iam using AJAX in JSP ... Lets say EMAIL_COMPONENT is my application and MainPage.jsp is default page where iam going to run AJAX..

Now ,

When the url path is http://localhost:8080/EMAIL_COMPONENT/JSP/MainPage.jsp
AJAX is working perfectly right ...

but

when the url is http://localhost:8080/EMAIL_COMPONENT/

AJAX is not working at all ...

What is the problem .... ???
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
What is your context root? EMAIL_COMPONENT or EMAIL_COMPONENT/jsp?

How did you define the default page? MainPage.jsp or jsp/MainPage.jsp?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What URL are you using when making your AJAX call?

How are you building it?
Can you post the JSP code that is used to create the URL?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Hi ,
Thanks for replying ... My context root is EMAIL_COMPONENT(Application Name) and i defined the default page as below in web.xml ...

<welcome-file-list>
<welcome-file>/JSP/MainPage.jsp</welcome-file>
</welcome-file-list>


My Web Folder Hierarchy ...

1)EMAIL_COMPONENT(Root)
1)JSP
2)JS
3)WEB-INF
Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Originally posted by Jesus Angeles:
What is your context root? EMAIL_COMPONENT or EMAIL_COMPONENT/jsp?

How did you define the default page? MainPage.jsp or jsp/MainPage.jsp?


Hi ,
Thanks for replying ... My context root is EMAIL_COMPONENT(Application Name) and i defined the default page as below in web.xml ...

<welcome-file-list>
<welcome-file>/JSP/MainPage.jsp</welcome-file>
</welcome-file-list>


My Web Folder Hierarchy ...

1)EMAIL_COMPONENT(Root)

under this folder,
1)JSP
2)JS
3)WEB-INF
Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Originally posted by Ben Souther:
What URL are you using when making your AJAX call?

How are you building it?
Can you post the JSP code that is used to create the URL?


Hi,
Thanks for replying....

Iam calling a JSP(Servlet) in javascript to get the response from it ....
Here is the url JAVASCRIPT code ...


var url = "GetEmailsServlet.jsp?sender_email="+AJAX_FIELD.value;
createXMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = callback;
Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
hi,
Please help me ASAP

This is my problem .....


I have a problem in running AJAX in JSP ...

Here " EMAIL_COMPONENT " is my web application and my default page
( configured in web.xml ) is MainPage.jsp .

Here is configuration in web.xml
--------------------------------

<welcome-file-list>
<welcome-file>/JSP/MainPage.jsp</welcome-file>
</welcome-file-list>

when i run my application with the url ,

http://localhost:8080/EMAIL_COMPONENT/

AJAX is not working ...

But when i explicitly hard code the url as below ...

http://localhost:8080/EMAIL_COMPONENT/JSP/MainPage.jsp

AJAX is working perfectly ....

Can anyone help me ASAP ....

Thanks in Advance ...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You're using a relative URL when making your AJAX call.



Like any link in a JEE app, the best approach is to make the link relative to the context path, not the current file.
Try:


Or, if you're using JSP 1.2:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX Problem in JSP