[英]Servlet doPost method
This is a simple html page: 这是一个简单的html页面:
<!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. 此html页面的形式称为servlet,在web.xml中具有/ get_Post作为url映射。
Now, this is doPost method of the servlet: 现在,这是servlet的doPost方法:
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. 我预计会出现空指针异常,而servlet会获取我以html形式输入的密码。 What can I do to make private password information?
如何制作私人密码信息?
If you're worried about security you need to enable SSL. 如果您担心安全性,则需要启用SSL。 For tomcat;
对于雄猫 first create a keystore and then add an SSL connector description to
server.xml
首先创建密钥库,然后将SSL连接器描述添加到
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. 然后将登录请求转发到HTTPS页面,并在授权后重定向到HTTP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.