Consider the code in the LoggingFilter filter: @Override
4 phương ánCó giải thích
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á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: "1-4-2-5-3". Chuỗi filter là một cái phễu hai chiều: filter khớp mẫu bao trùm nhận yêu cầu trước nên nó in ngày hiện tại, rồi lời gọi chain.doFilter mới đẩy yêu cầu đi tiếp tới index.jsp; container dịch trang JSP thành servlet, biên dịch rồi chạy để sinh HTML; khi phương thức của trang trả về, luồng điều khiển quay lại đúng chỗ ngay sau chain.doFilter trong filter, và chỉ sau khi filter kết thúc thì nội dung mới được đẩy ra trình duyệt. "1-5-4-2-3" sai vì phản hồi không thể quay về filter trước khi yêu cầu kịp tới index.jsp. "1-2-5-3" sai vì bỏ mất bước yêu cầu đi tiếp tới index.jsp, mà thiếu lời gọi chain.doFilter thì trang không bao giờ được chạy. "1-4-5-3" sai vì bỏ mất bước container xử lý trang JSP để sinh HTML, nghĩa là không có nội dung nào để trả về.
Cùng phần 10
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây