I want to load an Ajax loader image on clicking the href link with id="test". After clicking this href I want to call a Jsp Servlet which will sent an new request to load an new .jsp page.
The problem at this moment is that the servlet will be called, but it doesn't do an request to a new page. Can anybody help me out?
My code looks like this:
jsp page: href link and loader div
<div id="load"></div><a href="#" id="test" title="#" class="mainLink">link</a>
Servlet:
public class TestController extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // redirect to post doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // send to new jsp page request.setAttribute(getServletContext().getInitParameter("DynamicContentLoader"),"/secure/pages/test/testPage.jsp"); request.getRequestDispatcher("/collector.jsp").include(request, response); }}
Ajax call:
<script type="text/javascript"> $("#test").click(function(e){ e.preventDefault(); $.ajax({ type: "POST", url: "secure/TestController.do", beforeSend : function(xhr, opts){ //show loading gif $('#load').addClass('loader'); }, success: function(){ // nothing to do at this time }, complete : function() { //remove loading gif $('#laden').removeClass('loader'); } }); });</script>
This is the part which will include a new jsp page by the servlet responseDispatcher:
<c:when test="${not empty requestScope.includeJspContent}"><!-- start Dynamic Generated Context --><jsp:include page="${requestScope.includeJspContent}" /><!-- end Dynamic Generated Context --></c:when><c:otherwise><!-- start no dynamic data found --><jsp:include page="/error/no_dynamic_content.jsp" /><!-- end no dynamic data found --></c:otherwise>