為什么我這HTML中輸出不了“用戶(hù)名“和“密碼”?
@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>"+"用戶(hù)名:"+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"));
? ?}
}
2018-09-07
text/html;charset=utf-8
2018-08-06
既用了注解@WebServlet(name = "Servlet-init")
又使用了web.xml配置,<servlet-name>ServletInit</servlet-name>
2017-09-02
2017-09-02
web.xml 文件可以粘出來(lái)看看嘛