(十一)——LoginServlet & RegisterServlet
阿新 • • 發佈:2018-09-07
esp socket body override 兩個 tle erro ram bsp
這裏附上我寫的兩個類
1 package my.tomcat2; 2 3 import java.net.Socket; 4 5 public class LoginServlet extends Servlet { 6 7 @Override 8 public void doGet(Request request, Response response) { 9 String username = "feng"; 10 int password = 123; 11 String getUsername = request.getParam("username");12 String getPassword = request.getParam("password"); 13 14 if (getUsername.equals(username) && getPassword.equals(Integer.toString(password))) { 15 response.print("<html lang=\"en\"><head><meta charset=\"UTF-8\"><title>努力</title></head><body><h1>");16 response.print(request.getParam("username") + "最是人間留不住,朱顏辭鏡花辭樹</h1></body></html>"); 17 response.pushToClient(200); 18 }else { 19 response.print("<html lang=\"en\"><head><meta charset=\"UTF-8\"><title>努力</title></head><body><h1>");20 response.print(request.getParam("username") + "ERROR</h1></body></html>"); 21 response.pushToClient(200); 22 } 23 } 24 25 @Override 26 public void doPost(Request request, Response response) { 27 28 } 29 }
1 package my.tomcat2; 2 3 import java.net.Socket; 4 5 public class RegisterServlet extends Servlet { 6 7 @Override 8 public void doGet(Request request, Response response) { 9 response.print("<h1>Hi</h1>"); 10 response.pushToClient(200); 11 } 12 13 @Override 14 public void doPost(Request request, Response response) { 15 16 } 17 }
(十一)——LoginServlet & RegisterServlet