Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java response.sendRedirect不';我无法跟踪ip_Java_Jsp_Servlets_Response.redirect - Fatal编程技术网

Java response.sendRedirect不';我无法跟踪ip

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.

我将login.jsp重定向到index.jsp,语法如下:

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()

这会有用的