可返廻站點的根路逕request.getContextPath()
包com . v 512 . web project 2;
導入Java . io . io exception;
導入Java . io . printwriter;
導入javax . servlet . servlet exception;
導入javax . servlet . http . http servlet;
導入javax . servlet . http . http servlet request;
導入javax . servlet . http . http servlet response;
公共類LoginFormServlet擴展HttpServlet {
公共void doGet(HttpServletRequest請求,HttpServletResponse響應)
throws ServletException,io exception {
response . set content type(" text/html;charset = utf-8");
PrintWriter out = response . getwriter();
out . println("");
out . println("");
out.println("一個Servlet");
out . println("");
out . print("");
out.println("用戶名:""
");
out.println("秘密代碼:""
");
out . println("");
out . print("");
out . print("");
out . println(" request . getcontextpath"" the name web project 2""
");
out.println("通過帖子提交提交到自己的帖子""
");
out . println(" Resolve garbaged code request . setcharacter encoding(\" UTF-8 \")""
");
out . println("");
out . println("");
out . flush();
out . close();
}
public void doPost(http servlet request請求,HttpServletResponse響應)
拋出ServletException,io exception {
response . set content type(" text/html;charset = utf-8");
PrintWriter out = response . getwriter();
out . println("");
out.println("一個Servlet");
out . println("");
request . setcharacterencoding(" utf-8");
out.print("用戶名:" request.getparameter("用戶名")"
");
out . print(" secret code:" request . getparameter(" password")"
");
out . println("");
out . println("");
out . flush();
out . close();
}
}
0條評論