简体   繁体   English

jsp重定向url标签和response.sendRedirect()方法的区别

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

I have the following code to redirect to a new page from a jsp.我有以下代码可以从 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.我想知道response.sendRedirect<c:redirect url=之间的确切区别是什么任何人都可以帮助我了解重定向在这两种情况下的工作方式有何不同。 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.我相信您已经知道标签c:redirect是来自 JSTL(JSP 标准标签库)的标签,用于将请求重定向到另一个资源。 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.与任何 JSP 标记一样,使用它的好处是生成动态 HTML,而无需将 Java 代码(例如response.sendRedirect("someJspPage.jsp"); )与 HTML 标记混合。

It also supports c:param eg它还支持c:param例如

<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的情况下,您必须这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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