第一个javaweb程序,doget和dopost的区别

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class  extends HttpServlet {

private static final long serialVersionUID = 1L;


// doGet方法可以通过地址栏直接访问 不安全 doPost方法只能通过表单来访问

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("doget");
}


protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("doPost");
// 使用request对象来取页面上的对象
// 转码必须放在第一句
req.setCharacterEncoding("UTF-8");
String username = req.getParameter("username");
String upassword = req.getParameter("upassword");
System.out.println(username);
System.out.println(upassword);
}

}