





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























J4 PROGRAMMING – SERVLET/JSP & JPA
Conceive Design Implement Operate
URL mapping with servlet
Service methods
Simple form parameter handling
Read multi-valued parameters
Understanding servlet lifecycle and multithreading
The servlet receives requests, processes business, interacts with
the database, etc.
JSP generates interfaces (HTML, CSS, JS...) to respond to the user
Servlet is a class that inherits from HttpServlet provided by Sun
Override the service method (service(), doGet(), doPost()) to
handle the request from the user. In there
doGet(): Handle GET request
doPost(): Handle POST request (submit form with POST method)
service(): Handles both types of requests (when overriding this method,
doGet() and doPost() are disabled).
Không
phân biệt
POST hay GET
Có phân biệt^ POST và GET
http://.../crud/index
http://.../crud/edit/
http://.../crud/edit/TeoNV
http://.../crud/edit/...
http://.../crud/create
Tổ chức một Servlet
doGet(HttpServletRequest, HttpServletResponse)
doPost(HttpServletRequest, HttpServletResponse)
service(HttpServletRequest, HttpServletResponse)
In there
HttpServletRequest: is an object containing data sent from the browser
(parameters, cookies, headers) and some other system parameters (ip, server
name ...)
HttpServletResponse: is the object containing the response data about the client
Gõ vào ô địa chỉ của trình duyệt
<a href=“… / btec ”>Liên kết
@WebServlet(“ / btec ”)
do Post ()
do Get ()
POST: /poly
GET: /poly
GET request (link) to display the
form (call doGet())
POST request (submit form) to
process data entered into the form
(call doPost())
GET : http://… /login/form
POST : http://… /login/check
Method=“GET” then the form data is collected and formed into a
query string (appended after the? of the url) to be sent to the
server.
Method=“POST” then the browser will create a separate channel
to transmit data to the server
GET is faster than POST but has some limitations like:
Small data
Only text allowed (cannot upload)
Exposing sensitive data (passwords and hidden fields)
POST overcomes the limitations of GET
Lấy giá trị mục chọn
Lấy giá trị radio được chọn
< input type=“checkbox”
name=“chk_”>
Lấy giá trị khi có check, null khi không
check