如何将requestdispatcher转发到远程URL [英] How to forward the requestdispatcher to a remote URL

查看:526
本文介绍了如何将requestdispatcher转发到远程URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从远程服务器使用HTML页面 http://www.mywebapp.com/sample.html 。我在同一HTML表单中将HTML URL作为隐藏表单传递,

Am having a HTML page http://www.mywebapp.com/sample.html which is used from remote server. am passing the HTML URL as hidden form like this in the same HTML form,

<form action="/myservlet?userid=12345" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Submit">
<input type="hidden" name="url" value="http://www.mywebapp.com/sample.html"/>
</form>

在我的servlet中,我得到了隐藏的URL http://www.mywebapp .com / sample.html 并将其存储为
String fieldValue = http://www.mywebapp.com/sample.html

In my servlet i got the hidden URL http://www.mywebapp.com/sample.html and stored it as String fieldValue = http://www.mywebapp.com/sample.html

现在当我尝试 RequestDispatcher 并将页面转发到这样的隐藏URL时,

Now When i try RequestDispatcher and forward the page to the hidden URL like this,

RequestDispatcher rd = req.getRequestDispatcher(fieldValue);
rd.forward(req, resp);

我的 ERROR 404

任何人都可以建议我解决这个问题。

Can anyone suggest me an idea to solve this.

已编辑

我真正想做的是,来自远程服务器HTML页面将请求我的REST Web服务。 Web服务的响应将以JSON输出。现在我想将此JSON响应发送到请求的HTML表单(即远程服务器HTML页面)

What i exactly want to do is, From a Remote Server a HTML page will request to my REST Web services. The response of the web service will be in JSON output. Now i want to send this JSON Response to the requested HTML form(i.e. to the Remote Server HTML page)

任何人都可以提出解决此问题的建议。
我们将不胜感激。

Can anyone suggest an idea to solve this. Your help will be appreciated.

推荐答案

您无法将请求转发到您的外部网址Web应用程序。您可能希望将重定向发送到此URL。请参阅 HttpServletResponse.sendRedirect()

You can't forward a request to a URL which is external to your webapp. You probably want to send a redirect to this URL instead. See HttpServletResponse.sendRedirect().

请参阅 JSP转发和重定向之间的区别

这篇关于如何将requestdispatcher转发到远程URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆