为什么我这HTML中输出不了“用户名“和“密码”?
@WebServlet(name = "Servlet-init")
public class Servletinit extends HttpServlet {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html,charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println("<h1>"+"用户名:"+this.getUsername()+"</h1><br>");
out.println("<h1>"+"密码:"+this.getPassword()+"</h1><br>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
public void init() throws ServletException{
this.setUsername(this.getInitParameter("username"));
this.setPassword(this.getInitParameter("password"));
}
}