Hi,
JQuery not able to load jsp page when it contains jsp sriptlets having reference to RequestContextUtils.
<%@ page import="org.springframework.context.ApplicationContext,org.springframework.web.servlet.support.RequestContextUtils,org.sunshine.location.LocationService,org.sunshine.domain.Location,java.util.List"%>
<%
out.println("request:" + request.getContextPath());
ApplicationContext locationContext = RequestContextUtils.getWebApplicationContext(request);
LocationService locationService = (LocationService) locationContext
.getBean("locationService");
List<Location> locations = locationService.getLocations();
out.println(locations);
%>
<table id="location-table" width="95%" bgcolor="f8f8ff" border="0"
cellspacing="0" cellpadding="5">
<c:forEach items="<%=locations%>" var="location">
<tr>
<td><c:out value="${location.id}" /></td>
<td><a href="index.htm?store=${location.id}"><c:out
value="${location.name}" /></a></td>
</tr>
</c:forEach>
</table>
The above jsp page works fine if I access it normally. But when I use JQuery's load / get method it fails.
$(document).ready(function(){
$("button").click(function(){
$.get("jsp/locations.jsp",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
or
$(document).ready(function(){
alert("locad");
$("#locations-column").load("jsp/locations.jsp");
});
I commented all the unnecessary code to find out the root cause. I found ApplicationContext locationContext = RequestContextUtils.getWebApplicationContext(request); statement makes jquery to not to load the page.
Can someone help me in know why this is happening? how can i solve this problem?
Thanks in advance
-Vijay Daniel