title: Is it possible to use a JSP as a template for a servlet?
body: <p>I've been intermixing JSPs and Servlets in the web app I'm building and I'm starting to find that my more complex JSPs end up containing a lot of code, which flies in the face of all the MVC lessons that have been pounded into me.  I know I can do this by just forwarding to the JSP, but this seems like a stupid hack.</p>
  
  <p>What I'd like to do is use a servlet to do processing and then send a set of values to the JSP to render the HTML and return the response.  Something along the lines of:</p>
  
  <pre><code>public class MyServlet extends HttpServlet {
   public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws IOException {
  
           // ... Do some processing
  
           resp.getWriter.print(renderJSP("mypage.jsp", values));
  
      }
  
  }
  </code></pre>
  
  <p>I've been poking around Sun's documentation and found this: <a href="http://java.sun.com/developer/technicalArticles/javaserverpages/servlets_jsp/" rel="noreferrer">http://java.sun.com/developer/technicalArticles/javaserverpages/servlets_jsp/</a>
  It seems like the JSP Model 2 architecture is exactly what I want to implement, but I cannot find an example of how one can set that up.  For technical reasons, I cannot use one of the more advanced template frameworks like Struts.  </p>
  
  <p>Is this possible or a lost cause?</p>