title: Loading a jsp page using JQuery
body: <p>I have a specific div in my page where I want to load all the subpages (I'm using JQuery for this). Before loading them I need to do some operations in the server, so I call my servlet and after all operations are done I want to load the .jsp page... but I have no idea how. </p>
  
  <p>With responseText being: </p>
  
  <pre><code>/SAJ/WebContent/WEB-INF/views/administracion/semestres/semestreIndex.jsp
  </code></pre>
  
  <p>(the route in my project structure where wanted .jsp is stored)</p>
  
  <p>I got it to write responseText in the div:</p>
  
  <pre><code>&lt;div id="content" class="testDiv" &gt;
  </code></pre>
  
  <p>using this:</p>
  
  <pre><code>function load() {
      $.ajax({
          type: "POST",
          url: "/SAJ/pages/semestre",
          success: function(responseText) {
              $('#content').text(responseText); 
          }
      });
  }
  </code></pre>
  
  <p>but I have no idea how to load the whole page. My first idea was to do this:</p>
  
  <pre><code>function load() {
      $.ajax({
          type: "POST",
          url: "/SAJ/pages/semestre",
          success: function(responseText) {
              $('#content').load(responseText); 
          }
      });
  }
  </code></pre>
  
  <p>But I get a 404 error in Chrome's console:</p>
  
  <pre><code>GET http://localhost:8080/SAJ/WebContent/WEB-INF/views/administracion/semestres/semestreIndex.jsp 404 (Not Found)
  </code></pre>
  
  <p>I suppose than I'm using the wrong route? But how can I find which one is the correct one? I'm just following my project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/Q2zjS.png" alt="Project structure"></p>
  
  <p><strong>Servlet code:</strong></p>
  
  <pre><code>protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
      try {
          Action action = ((ActionFactory) getServletContext().getAttribute("actions")).getAction(request);
          String view = action.execute(request, response);
          if(view.equals("index")){
              request.getRequestDispatcher("/WEB-INF/" + view + ".jsp").forward(request, response);
          }else{
              response.getWriter().write("/SAJ/WebContent/WEB-INF/" + view + ".jsp");
          }
      } catch (Exception e) {
          throw new ServletException("Executing action failed.", e);
      }
  }
  </code></pre>
  
  <p><strong>Action called by the servlet:</strong></p>
  
  <pre><code>public class SemestreListarAction implements Action{
  
      public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
      request.setAttribute("test", "HELLO WORLD!");
      System.out.println("I'm nice so I did some stuff for you!");
  
          return "views/administracion/semestres/semestreIndex";
      }
  }
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Redirector&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.saj.controller.Redirector&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Redirector&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/pages/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p><strong>Caller:</strong></p>
  
  <pre><code>&lt;a href="#" onclick="load()"&gt;Load&lt;/a&gt;
  </code></pre>