Note that there are some explanatory texts on larger screens.

plurals
  1. POPass value servlet to jsp
    primarykey
    data
    text
    <p>I want to pass value servlet to jsp. set value in servlet and use in jsp page</p> <p>I getting NullPointerException below is my code</p> <p><strong>jsp</strong></p> <pre><code>&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; </code></pre> <p><strong>java</strong></p> <pre><code>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); //communicating a Vector object Vector vecObj = new Vector(); vecObj.add("Servlet to JSP communicating an object"); request.setAttribute("vecBean",vecObj); //Servlet JSP communication RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("javaPapers.jsp"); reqDispatcher.forward(request,response); } } </code></pre> <p><strong>Error Log</strong> I didnt do any chnages in web.xml I didnt do any chnages in web.xml</p> <pre><code>org.apache.jasper.JasperException: An exception occurred processing JSP page /javaPapers.jsp at line 21 18: out.println("Servlet communicated message to JSP: "+ message); 19: 20: Vector vecObj = (Vector) request.getAttribute("vecBean"); 21: out.println("Servlet to JSP communication of an object: "+vecObj.get(0)); 22: %&gt; 23: &lt;/body&gt; 24: &lt;/html&gt; Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root cause java.lang.NullPointerException org.apache.jsp.javaPapers_jsp._jspService(javaPapers_jsp.java:83) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload