Consider the following filter mappings defined in the deployment descriptor of a Java web application:
4 phương ánCó giải thích
<filter-mapping>
<filter-name>filterOne</filter-name>
<url-pattern>/student*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filterTwo</filter-name>
<url-pattern>/student/add</url-pattern>
</filter-mapping>Which of the following statements most accurately describes the order in which these filters are processed for a request matching both URL patterns in a Java web application?
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: "filterOne is processed first because it is declared before filterTwo in the deployment descriptor.". Đặc tả quy định thứ tự chuỗi filter cho một yêu cầu được xếp theo mô tả triển khai: trước hết là các thẻ filter-mapping khớp theo khuôn địa chỉ, lấy đúng thứ tự xuất hiện trong tệp, rồi mới tới các thẻ khớp theo tên servlet. Vì cả hai khuôn ở đây đều khớp yêu cầu, mắt được gọi trước là mắt khai trước, không phụ thuộc khuôn dài hay ngắn. Lựa chọn giải thích "due to its alphabetical precedence over filterTwo" đưa ra tiêu chí không tồn tại: tên filter chỉ dùng để đối chiếu với thẻ khai báo filter, container không sắp theo thứ tự chữ cái. Lựa chọn cho rằng khuôn "is more specific than the generic pattern" thì nhầm luật của filter với luật chọn servlet, nơi khuôn cụ thể hơn thắng khuôn rộng hơn; với filter thì mọi khuôn khớp đều được dùng và dùng theo thứ tự khai báo. "Both filters are processed simultaneously." sai về cơ chế, vì chuỗi filter chạy tuần tự trên cùng một luồng, mắt sau nằm bên trong lời gọi của mắt trước.
Cùng phần 10
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây