title: RequestDispatcher Showing Page's source code Java Servlet
body: <p>Everything is working fine else <strong>why RequestDispatcher showing source code of page?</strong></p>
  
  <pre><code>public class LoginServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      @Override
      protected void doPost(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
          String uName=req.getParameter("uEmail");
          String uPass=req.getParameter("uPass");
          try{
              DBConnection con=new DBConnection();
              if(con.login(uName, uPass)){
                  HttpSession on = req.getSession();
                  on.setAttribute("u_id", uName);
                  res.sendRedirect("dashboard.jsp");
              }
              else{
                  RequestDispatcher dis= getServletContext().getRequestDispatcher("/login.jsp");
                  PrintWriter write = res.getWriter();
                  write.println("Wrong Username or Passowrd");
                  dis.include(req, res);
              }
          }catch(ClassNotFoundException | SQLException e){}
  
      }
  }
  </code></pre>
  
  <p>Page redirecting fine to given url <code>/login.jsp</code> and also showing the error message, but why as source code?</p>
  
  <pre><code>Wrong Username or Passowrd
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action="LoginServlet" method="POST" /&gt;
              &lt;input type="text" name="uEmail" /&gt;
              &lt;br /&gt;&lt;br /&gt;
              &lt;input type="text" name="uPass" /&gt;
              &lt;br /&gt;&lt;br /&gt;
              &lt;input type="Submit" name="Register" value="Register" /&gt;
              &lt;br /&gt;&lt;br /&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>direct link to <code>login.jsp</code> works fine.</p>