Java response.sendRedirect不';我无法跟踪ip
我将login.jsp重定向到index.jsp,语法如下:Java response.sendRedirect不';我无法跟踪ip,java,jsp,servlets,response.redirect,Java,Jsp,Servlets,Response.redirect,我将login.jsp重定向到index.jsp,语法如下: response.sendRedirect("index.jsp"); 在服务器上,当我访问localhost:8080测试应用程序时,它工作正常。 当我从另一台电脑远程浏览时,我需要服务器地址(比如xxx.xxx.xxx.xxx:8080),重定向会将我发送到localhost:8080/index.jsp,而本地机器上当然不存在这个地址。如果我写了这样的东西 response.sendRedirect("xxx.xxx.xxx.
response.sendRedirect("index.jsp");
在服务器上,当我访问localhost:8080测试应用程序时,它工作正常。
当我从另一台电脑远程浏览时,我需要服务器地址(比如xxx.xxx.xxx.xxx:8080),重定向会将我发送到localhost:8080/index.jsp,而本地机器上当然不存在这个地址。如果我写了这样的东西
response.sendRedirect("xxx.xxx.xxx.xxx:8080/index.jsp");
然后浏览器会丢失会话变量,这是我不想要的。
如何解决这个问题?试试这个
response.sendRedirect("/yourWebContext/index.jsp");
这会奏效的
xxx.xxx.xxx.xxx:8080/index.jsp
松开会话可能是因为浏览器没有发送它接收到的具有不同域名的cookie,请尝试使用requestDispatcher.forward()而不是response.sendRedirect() 这会有用的