gpt4 book ai didi

java - sendRedirect() 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:18 27 4
gpt4 key购买 nike

我在这个论坛上寻找解决方案,但没有找到适合我的问题的解决方案。

我有一个非常简单的代码

一个jsp页面

<html>
<body>
<jsp:include page="/servletName"/>
</body>
</html>

和一个servlet

@WebServlet("/servletName")
public class reindirizzaController extends HttpServlet {
private static final long serialVersionUID = 1L;

public reindirizzaController() {
super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String redirectURL = "http://www.google.it";
response.sendRedirect(redirectURL);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}

}

没有重定向。我被困在 jsp 页面中,没有收到任何错误。我还尝试在响应后添加 return;

最佳答案

因为您是通过Include 调用servlet,所以它不会让您重定向。它只是忽略。

来自 include() 的文档

includes the content of a resource (servlet, JSP page, HTML file) in the response. In essence, this method enables programmatic server-side includes.

The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.

关于java - sendRedirect() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25140571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com