简体   繁体   中英

Difference between jsp redirect url tag and response.sendRedirect() method

I have the following code to redirect to a new page from a jsp.

   //response.sendRedirect("someJspPage.jsp");  
   %>
      <c:redirect url="someJspPage.jsp" />
   <%       

I see the first line is commented out. But I am not sure why. I want to know what is the exact difference between response.sendRedirect and <c:redirect url= Can anyone help me out to understand how the redirection works differently in both cases. I am writing a solution for a mixed content issue but I need to understand this difference first.

Both of them work alike. I believe you already know that the tag, c:redirect is a tag from JSTL (JSP Standard Tag Library) and is used to redirect the request to another resource. Like any JSP tag, the benefit of using it is to generate dynamic HTML without mixing Java code (eg response.sendRedirect("someJspPage.jsp"); ) with HTML tags.

It also supports c:param eg

<c:redirect url="someJspPage.jsp" >
    <c:param name="someVar" value="1234"/>
</c:redirect>

In the case of response.sendRedirect , you will have to do it as:

response.sendRedirect("someJspPage.jsp?someVar=1234");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM