Note that there are some explanatory texts on larger screens.

plurals
  1. POrequest.getAttribute is null in servlet
    text
    copied!<p>I am setting the request.getAttribute as below in my jsp</p> <pre><code> &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;% request.setAttribute("name", "anita"); %&gt; &lt;%=request.getAttribute("name") %&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="POST" action="QnAAuthServlet"&gt; &lt;input type="hidden" name="orgName" value="SENDFORBOB"&gt;&lt;/input&gt; &lt;input type="submit"&gt;&lt;/input&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I am able to print it also in my JSP</p> <p>I am trying to request.getAttribute in my servlet as below</p> <pre><code> public class QnAAuthServlet extends HttpServlet { private static final long serialVersionUID = 1L; public QnAAuthServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { enter code here String name = (String) request.getAttribute("name"); System.out.println("name = " + name); } } </code></pre> <p>But name is always null in my servlet. Please someone help me to resolve this.</p>
 

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