English 中文(简体)
Java Servlet - 从子页面转发/重定向
原标题:Java servlet - Forwarding/Redirecting from subpage

我正在研究一个工程,在战争中我运行了套装的服务器,在战争中倾听请求,并在单独的页面上播放外国迪维。初始请求是向服务器 (a) 提出,如果需要显示数据,则会生成 HTML 。如果没有数据,它会将查询字符串传送到另一个服务器,以便处理请求,然后提供一个有选项选择的页面。

我正在用Windows Server 2008 运行 Tomcat 6。

但我遇到了两个问题:

  1. When I use redirect, I get no response from the servlet being redirected to. I have some javascript alerts up that are never called by the (b)
    servlet. I AM using relative paths and confirm the link is correct in logs.
  2. When I copy that link in step 1 in a new window, I see the results. Just not when it s embedded in another page that makes the request. Why would that be? Is it possibly a limitation from the host page and not being able to render the response?
  3. When I use a forward, I see the servlet response, but then a new window opens. Thus taking the person away from the original page. This would be great if the results render in the same page.

有什么最佳做法可以保证我能够使用第一个服务器的响应对象,从最初的服务器调用到另一个服务器的“转机”呢?

最佳回答

重定向返回客户需要处理的新 URL < code>Location 头中的 HTTP 302 回复。 基本上, 您的 JS 代码如果是 302 则必须检查回复状态代码, 然后提取 < code>Location 头, 然后对它重新发送新的请求 。 重复一遍, 直到回复状态代码为 200 。

当在浏览器地址栏中粘贴 URL 地址栏时, 这是有效的, 因为浏览器已经知道如何正确处理 3nn 响应 。 如果您在浏览器 s Web Developers 工具栏中打开网络流量跟踪器, 那么您就会看到第二个 Get 请求被新 URL 激活 。

另一种方式是,如果服务器在同一容器中运行,只需使用 requestDispatcher #forward () ,而不是 Http ServletResponse#sendRepirect ()

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签