我是Java的新手,似乎我的Servlet中出现了问题,因为我在chrome浏览器中不断获取net::ERR_TOO_MANY_REDIRECTS
,而且我在浏览器中输入的任何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>
HomeServlet.xml
@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");
}
}
请告诉我上面出了什么问题。