We have in our application a need for our servlet to be redirected to a document and we dont want the URL of the document not to be displayed in the browser. sendRedirect does show the URL. Any ideas? Thanks...
I noticed something interesting a few days ago using getServletContext().getRequestDispatcher( "/servletname" ).forward( request, response ) I forwarded from one servlet to another mapped servlet (e.g. from "/servlet1" which received the initial doGet(), to "/servlet2") and after validation, my attempt to use request dispatcher to forward BACK to "/servlet1" gave me the error "can not forward to same name URI" out of JRun's wrapper for request dispatcher. Since /servlet1 and /servlet2 have different mappings, aren't they different URIs??? I received this bug against JRun 2.3.3; I had meant to test it against JRun 3.x but in the meantime I simply have /servlet2 do a sendRedirect( ".../servlet1" ). Is this probably just a bug in my servlet container, or does it seem as if this exception is logical? TIA. [ March 02, 2002: Message edited by: matt horton ]
Couldn't you use RequestDispatcher.include()? (This can be retrieved either through the ServletRequest or the ServletContext, depending on whether the new resource is in the same webapp or not and whether it is public or not.) This does not change the path elements in the response object, and hence should give no indication whatsoever to the user that the source URL of the response is different than the one requested. I haven't tried this, but it is what I would try if I were you (and assuming I am understanding your problem correctly).
vasu, two people have given you potential solutions, but to re-iterate:
You have somewhat conflicting requirements. If you *need* the browser to be redirected, then you have no choice but to show *what* you are redirecting to in the browser's address bar. This is not up to you, it is the browser that is displaying the information.
Your remaining choices are foward() and include(). Since the resource is potentially a pdf file, your last remaining choice is forward(). web.xml Place the servlet inside the /webapps/examples/WEB-INF/classes directory, and put redir.pdf at /webapps/examples
I think you should use the HttpResponse of a servlet to wrap your pdf document. - "Hide" your file in the WEB-INF dir (I am a tomcat user) - Use the getResourceAsStream() method of the ServletContext Object to get an InputStream Object corresponding to your file. - Change the MIME type of your response by using the setContentType() method according to the MIME type of your file. - "Copy" the inputStream content to the HttpResponse PrintWriter (a decoration will be needed) ... Am I right ??? Nicolas
<a href="http://www.javablackbelt.com/?utm_source=javaranch&utm_medium=signature&utm_campaign=Forum%2BBuzz" target="_blank" rel="nofollow">BlackBeltFactory Communtiy</a> founder - Building better developers<br /><b>Free</b> courses and mock exams