This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX Problem in JSP

 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic