title: servlet to jsp pass value
body: <p>I want to simple pass value servlet to jsp page. I want to run jsp file and onload data is display from getting servlet</p>
  
  <p>But I got null : <code>"Servlet communicated message to JSP: null "</code></p>
  
  <p>below is my code.</p>
  
  <p><strong>java code</strong></p>
  
  <pre><code>package api;
  
  public class ServletToJSP extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          //communicating a simple String message.
          String message = "Example source code of Servlet to JSP communication.";
          request.setAttribute("message", message);
  
          RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("javaPapers.jsp");
          reqDispatcher.forward(request,response);
  
  
        }
  }
  </code></pre>
  
  <p><strong>jsp file</strong></p>
  
  <pre><code>&lt;%@ page import="api.ServletToJSP" language="java" %&gt;
  
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;%
    String message = (String) request.getAttribute("message");
    out.println("Servlet communicated message to JSP: "+ message);
  
   // Vector vecObj = (Vector) request.getAttribute("vecBean");
  //  out.println("Servlet to JSP communication of an object: "+vecObj.get(0));
  %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;servlet&gt;
        &lt;servlet-name&gt;ServletToJSP&lt;/servlet-name&gt;
        &lt;servlet-class&gt;api.ServletToJSP&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
  
        &lt;servlet-name&gt;ServletToJSP&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/ServletToJSP/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>