java net::ERR_TOO_MANY_重定向并显示任何URL的空白页
我是Java新手,我的Servlet似乎有问题,因为我在chrome浏览器中不断获得java net::ERR_TOO_MANY_重定向并显示任何URL的空白页,java,jsp,servlets,jakarta-ee,Java,Jsp,Servlets,Jakarta Ee,我是Java新手,我的Servlet似乎有问题,因为我在chrome浏览器中不断获得net::ERR\u太多重定向,并且我在浏览器中输入的任何URL都显示空白页面 下面是代码: web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2e
net::ERR\u太多重定向
,并且我在浏览器中输入的任何URL都显示空白页面
下面是代码:
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>My Application</display-name>
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
<name>mysessionid</name>
<http-only>true</http-only>
</cookie-config>
</session-config>
</web-app>
@WebServlet("/")
public final class HomeServlet extends HttpServlet {
private HttpSession session = null;
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
session = request.getSession(false);
System.out.println("session::: "+ session);
if(session != null && !session.isNew()) {
System.out.println("inside session only!");
response.sendRedirect("index.html");
} else {
something(request, response);
}
}
private String something(HttpServletRequest request, HttpServletResponse response) throws IOException {
if(accessToken != null) {
session = request.getSession();
response.sendRedirect("index.html");
}
}
请告诉我上面出了什么问题。你能调试一下吗?我假设每次您重定向到'index.html'请求都会再次由您的servlet处理,并且您再次重定向到'index.html',因此这是重定向循环。有人可以尝试研究一下吗?请有人在上述问题上帮助我。。