简体   繁体   中英

Servlet doPost method

This is a simple html page:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="ISO-8859-1">
            <title>GET_POST</title>
    </head>
    <body>

       <h5> Insert username and password  </h5>

       <form action ="./get_Post" method ="post">
           username: <br>
           <input type = "text" name = "username">
           <br>
           password:<br>
           <input type = "password" name ="password">
           <br><br>
           <input type = "submit" value = "LOGIN">
       </form>
    </body>
</html>

The form of this html page called the servlet has /get_Post as url-mapping in web.xml.

Now, this is doPost method of the servlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String password = request.getParameter("password");
    PrintWriter out = response.getWriter();
    out.println(password);
}

I expected null pointer exception, and instead the servlet gets the password I put in the html form. What can I do to make private password information?

If you're worried about security you need to enable SSL. For tomcat; first create a keystore and then add an SSL connector description to server.xml

<Connector port="8443" scheme="https" secure="true" SSLEnabled="true"
   keystoreFile="somekeystore" sslProtocol="TLS"
   keystorePass="pwd" />

Then forward login requests to HTTPS page and redirect to HTTP after authorization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM