What method must be implemented by all filters?
5 phương ánCó giải thích
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: "doFilter". Mọi bộ lọc đều phải hiện thực phương thức này vì đó là chỗ container trao cặp yêu cầu, phản hồi cùng tham chiếu chuỗi bộ lọc; cho chuỗi đi tiếp thì lượt yêu cầu đi sâu vào bộ lọc sau rồi tới servlet, còn không gọi thì bộ lọc chặn lại ngay. Phương thức "doGet" nằm trong servlet HTTP và chỉ chạy cho lượt yêu cầu dùng phương thức đọc, nó không có trong giao diện bộ lọc. Phương thức "doPost" cũng của servlet HTTP, dành riêng cho lượt gửi dữ liệu lên. Phương thức "service" là điểm vào của servlet, nơi phân nhánh theo phương thức HTTP, đứng sau toàn bộ chuỗi bộ lọc. Phương thức "init" có trong vòng đời bộ lọc nhưng mang thân mặc định nên không buộc phải viết lại, và nó chỉ chạy một lần lúc khởi tạo chứ không xử lý yêu cầu.
Cùng phần 10
Which XML elements are used to define a servlet filter in the web.xml file?Có lời giảiCâu hỏiWhat happens to request attributes when sendRedirect() is used? request.setAttribute("data", "value"); response.sendRedirect("result.jsp");Có lời giảiCâu hỏiConsider the code in the LoggingFilter filter:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
System.out.println( new Date());
chain.doFilter(request, response);
}
And in the web.xml:
<filter>
<filter-name>LoggingFilter</filter-name>
<filter-class>LoggingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Assuming that the client sends a request to open the index.jsp page, arrange the following steps correctly to describe the processing inside server.
1: the LoggingFilter intercepts the request to display current date
2: the server compiles and processes the JSP file to generates an HTML response.
3: The final HTML content from index.jsp is sent back to the client's browser.
4: the request continues to index.jsp
5: the HTML response from index.jsp is sent back to the LoggingFilter.Có lời giảiCâu hỏiCả 26 câu của chủ đề26 câu
Xuất hiện trong 3 bộ đề
Đi tiếp từ đây