Which method is mandatory in a Filter class?
4 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". Giao diện bộ lọc đặt toàn bộ phần việc chặn tại phương thức này: nó nhận cặp yêu cầu, phản hồi và tham chiếu chuỗi bộ lọc, làm việc trước khi cho chuỗi đi tiếp, rồi còn có thể làm thêm việc sau khi lượt gọi quay về; không cho chuỗi đi tiếp thì lượt yêu cầu dừng ngay tại đó. Phương thức "service" thuộc servlet, là nơi container đẩy yêu cầu vào sau khi mọi bộ lọc đã cho qua, nên không nằm trong giao diện bộ lọc. Phương thức "execute" không có trong giao diện này, đó là tên quen thuộc ở các khung khác chứ không phải phần của đặc tả servlet. Phương thức "initFilter" là tên sai: vòng đời bộ lọc dùng hàm khởi tạo nhận cấu hình và hàm dọn khi tháo, mà hai hàm đó lại có thân mặc định nên không buộc phải viết.
Cùng phần 10
What is the first method called when a filter is initialized in a web application?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 1 bộ đề
Đi tiếp từ đây