What is the purpose of the @WebServlet annotation in the example? @WebServlet(name="HelloServlet", urlPatterns={"/hello"})
4 phương ánCó giải thích
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.getWriter().println("<h1>Hello from @WebServlet!</h1>");
}
}Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "It replaces the XML servlet declaration in web.xml". Annotation này mang đúng những thông tin mà trước đây phải viết thành khối khai báo servlet cộng khối ánh xạ servlet trong mô tả triển khai: thuộc tính name đặt tên servlet, thuộc tính mẫu URL nêu đường dẫn mà container sẽ gọi tới lớp này, nhờ vậy lớp trong ví dụ phục vụ được đường dẫn của nó mà không cần thêm dòng nào vào tệp cấu hình. Lựa chọn "It configures cookies and sessions" không thuộc phần việc của annotation này; cookie và phiên được tạo cùng đọc trong mã, còn thời gian chờ phiên khai ở mô tả triển khai. Lựa chọn "It disables servlet loading at startup" hiểu sai: việc nạp sớm do một thuộc tính riêng quyết định, ở ví dụ này thuộc tính đó không xuất hiện, và mặc định là nạp khi có request đầu tiên chứ không phải bị tắt. Lựa chọn "It defines the servlet’s security policy" là việc của annotation bảo mật riêng hoặc của khối ràng buộc bảo mật.
Cùng phần 2
What is the ServletContext in a Java web application?Có lời giảiCâu hỏiWhat is the purpose of the error-code element in the <error-page> configuration of the web.xml file in a Java web application?Có lời giảiCâu hỏiWhich method is invoked most during servlet operation?Có lời giảiCâu hỏiCả 48 câu của chủ đề48 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây