Note that there are some explanatory texts on larger screens.

plurals
  1. POdoGet and doPost in Servlets
    primarykey
    data
    text
    <p>I've developed an HTML page that sends information to a Servlet. In the Servlet, I am using the methods <code>doGet()</code> and <code>doPost()</code>:</p> <pre><code>public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String id = req.getParameter("realname"); String password = req.getParameter("mypassword"); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String id = req.getParameter("realname"); String password = req.getParameter("mypassword"); } </code></pre> <p>In the html page code that calls the Servlet is:</p> <pre class="lang-html prettyprint-override"><code>&lt;form action="identification" method="post" enctype="multipart/form-data"&gt; User Name: &lt;input type="text" name="realname"&gt; Password: &lt;input type="password" name="mypassword"&gt; &lt;input type="submit" value="Identification"&gt; &lt;/form&gt; </code></pre> <p>When I use <code>method = "get"</code> in the Servlet, I get the value of id and password, however when using <code>method = "post"</code>, id and password are set to <code>null</code>. Why don't I get the values in this case?</p> <p>Another thing I'd like to know is how to use the data generated or validated by the Servlet. For example, if the Servlet shown above authenticates the user, I'd like to print the user id in my HTML page. I should be able to send the string 'id' as a response and use this info in my HTML page. Is it possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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