title: Pass values from Servlet to an onload JavaScript function in a JSP
body: <p>I am using the following code in my <em>Servlet</em> to set the Attribute <em>confirmMsg</em> :</p>
  
  <pre><code>req.setAttribute("confirmMsg", "Update Values");
  </code></pre>
  
  <p>This I'm forwarding to the JSP</p>
  
  <pre><code>RequestDispatcher rd = req.getRequestDispatcher("displayDetails.jsp");
  rd.forward(req, resp);
  </code></pre>
  
  <p>In my JSP, I need to display the message when the page loads. </p>
  
  <pre><code>&lt;body onload = "showConfirmMsg();"&gt;
  
  // .....
  
  &lt;/body&gt;
  </code></pre>
  
  <p>What should I do in the following function, so as to show the message onload itself?</p>
  
  <pre><code>function showConfirmMsg() {
  
  // Code to show the alert box onload
  
  }
  </code></pre>