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>
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
Now When i try RequestDispatcher
and forward the page to the hidden URL like this,
RequestDispatcher rd = req.getRequestDispatcher(fieldValue);
rd.forward(req, resp);
am getting ERROR 404
.
Can anyone suggest me an idea to solve this.
EDITED
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.
SendRedirect() will search the content between the servers. it is slow because it has to intimate the browser by sending the URL of the content. then browser will create a new request for the content within the same server or in another one. RquestDispatcher is for searching the content within the server i think.
The RequestDispatcher interface provides the option of dispatching the client's request to another web resource, which could be an HTML page, another servlet, JSP etc. It provides the following two methods: public void forward(ServletRequest request, ServletResponse response)throws ServletException, java. io.
We can use request dispatcher only when the other servlet to which the request is being forwarded lies in the same application. On the other hand Send Redirect can be used in both the cases if the two servlets resides in a same application or in different applications.
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()
.
See Difference between JSP forward and redirect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With