Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

forwarding to servlet

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using this code to forward the page to the PDFDisplay servlet, because I want to display a byte[] array of images in PDFDisplay page.

RequestDispatcher rd = request.getRequestDispatcher("PDFDisplay");
rd.forward(request,response);

The code in PDFDisplay is working and displaying the image which I want to display. But the image is displayed in the old page. The url is not changing in the webbrower. What should I do to change the url to point to this servlet page. Any pointer would be greatly appreciated.

Thanks.
 
author
Posts: 4281
34
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the PDFDisplay servlet? This sounds like some proprietary (unless my memory is foggy) and should probably be asked to the manufacturers of the servlet.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the forwarding is done by web server, so client does not know about this forwarding. Thats why browser url will not change with forward. But still the servlet container will execute the service method of PDFDisplay Servlet.

Naseem
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

PDFDisplay.java is the servlet name.

Is there is any way to change the url while forwarding.

Thanks.
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cathymala louis:

Is there is any way to change the url while forwarding.



No. That's the whole point of a forward, that it executes within the context of a single request.

Why is what is showing in the URL bar of the browser an issue?
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because I want to go to the previous page by clicking back button. To choose a different image id. Is there is any other way to approach this problem.
 
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cathymala louis:
Hi

PDFDisplay.java is the servlet name.

Is there is any way to change the url while forwarding.

Thanks.



Well, sendRedirect() works like you wish.

So, make an entry in web.xml like this:



Now, write this code where you are forwarding currently:



You can also change extension (pdf to java or anything) at both the place.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it will work fine with above file
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic