Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình

Cách dùng tag <c:redirect> trong JSP

Tag <c:redirect> chuyển hướng browser đến URL thay thế, hỗ trợ tự động URL rewriting, context-relative URLs, và tag <c:param>.

Thuộc tính

AttributeDescriptionRequiredDefault
urlURL chuyển hướng browserYesNone
context/ theo sau tên web app localNoCurrent application

Ví dụ

Cần truyền tham số cho <c:import>, dùng <c:url> tạo URL trước:

<%@ taglib uri = "https://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
  <head> <title><c:redirect> Tag Example</title> </head>
  <body>
    <c:redirect url = "https://www.photofuntoos.com" />
  </body>
</html>

Code trên chuyển request đến https://www.photofuntoos.com.