title: forwarding from spring controller to a jsp file
body: <p>I am trying to forward my request from a Spring-MVC controller method - to a JSP page.</p>
  
  <p>My controller method is supposed to <strong>handle an Ajax request</strong>. By <strong>forwarding the request to the JSP file</strong>, I want the response to the Ajax request to be the (dynamic) HTML <strong>output of the JSP file</strong>.</p>
  
  <p>What I have tried:</p>
  
  <pre><code>public ModelAndView ajaxResponse(HttpServletRequest request, HttpServletResponse response) {
  
      request.setAttribute("command", "hello world");
  
      request.getRequestDispatcher("jspfile").forward(request, response);
      return null;    
  }
  </code></pre>
  
  <p>This fails and I get "HTTP Status 404"</p>
  
  <p>"jspfiles" is defined in a tiles config file to be directed to the actual jsp file. When I run the following method:</p>
  
  <pre><code>public String ajaxResponse(HttpServletRequest request, HttpServletResponse response) {
  
      request.setAttribute("command", "hello world");
      return "jspfile";
  }
  </code></pre>
  
  <p>... I get the content of the file as my Ajax response - but JSP tags in that file are not parsed) - hence I conclude that my tiles definition is correct (???).</p>
  
  <p>My JSP file looks like this:</p>
  
  <pre><code>&lt;%=command%&gt;
  </code></pre>
  
  <p>So I want to get as my Ajax response the string "hello world".</p>
  
  <p>Could you show me an example code of how to achieve my purpose?</p>
  
  <p>Specifically I need to know:</p>
  
  <ol>
  <li><p>What should be the controller method return type?</p></li>
  <li><p>What should be the controller method actual return value (if it matters)?</p></li>
  <li><p>How should I set the jsp file path in the <code>request.getRequestDispatcher(...)</code> so it would be recognized?</p></li>
  </ol>