title: Spring mvc el only works when jsp in WEB-INF?
body: <p>I just learned servlet and now getting to learning Spring MVC. I just couldn't get my head wrapped around this</p>
  
  <p>Normal jsp servlet I use EL to access session.attribute without putting jsp within WEB-INF, but with Spring MVC it seems like I have to put JSP file within WEB-INF for EL to work why is this? or am I just doing something wrong?</p>
  
  <p>Example Servelet (Working example):</p>
  
  <p>Index.jsp</p>
  
  <pre><code>&lt;form id="form" action="form-el" method="POST"&gt;
          &lt;label for="firstName"&gt;First Name: &lt;/label&gt;
          &lt;input type="text" name="firstName"&gt;
          &lt;button type="submit"&gt;Click Me&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;div id="result&gt;
    &lt;p&gt;${name}
  &lt;/div&gt;
  </code></pre>
  
  <p>Servlet:</p>
  
  <pre><code>public class formServlet extends HttpServlet
  {
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
          String firstName = request.getParameter("firstName");
  
          String url ="/index.jsp";
  
          ServletContext cs = getServletContext();
  
          HttpSession session = request.getSession();
          session.setAttribute("firstName", firstName);
          session.setAttribute("lastName", lastName);
  
          cs.getRequestDispatcher(url).forward(request, response);
      }
  }
  </code></pre>
  
  <p>Spring: (Working example) </p>
  
  <p>File structure:</p>
  
  <pre><code>|-WebContent
      |-WEB-INF
           |-html
               -index.jsp
           - offers-dispatcher-servlet.xml
           - web.xml 
  </code></pre>
  
  <p>Index.jsp</p>
  
  <pre><code>${name}
  </code></pre>
  
  <p>offers-dispatcher-servlet.xml</p>
  
  <pre><code>&lt;context:component-scan base-package="com.caveofprogramming.pring.web.controllers"&gt;
  &lt;/context:component-scan&gt;
  
  &lt;mvc:annotation-driven&gt;&lt;/mvc:annotation-driven&gt;
  
  &lt;mvc:resources mapping="/resources/**" location="/" /&gt;
  
  &lt;bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
  &lt;property name="prefix" value="/WEB-INF/html/"&gt;&lt;/property&gt;
  &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>@Controller
  </code></pre>
  
  <p>public class OffersController {</p>
  
  <pre><code>@RequestMapping("/")
  public String showHome(HttpSession session){
      // Return logical name of the view to use. The actual job of figuring out
      // what view to load is something called "viewResolver"
      session.setAttribute("name", "Tim");
      return "index";
  }
  </code></pre>
  
  <p>=============================</p>
  
  <p>Now if I move index.jsp outside of WEB-INF and change offers-dispatcher-servlet.xml</p>
  
  <pre><code>&lt;bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
  &lt;property name="prefix" value="/"&gt;&lt;/property&gt;  &lt;!-- Change directory --&gt;
  &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>New File structure:</p>
  
  <pre><code>|-WebContent
      |-WEB-INF
           - offers-dispatcher-servlet.xml
           - web.xml
       -index.jsp 
  </code></pre>
  
  <p>This no longer works, returns null... could someone help to explain?  Thank you.</p>