wood burning stoves*
The moose likes Servlets and the fly likes forwarding to an outside URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "forwarding to an outside URL" Watch "forwarding to an outside URL" New topic
Author

forwarding to an outside URL

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I've written a web app that has a servlet that reads from a database a list of names and corresponding pager numbers, and forwards to a JSP that calls a custom tag to build an XML style JSP from the ResultSet (saved in the session), and includes that JSP in a frame on the calling JSP. Someone can then select a name, type in a message, and click submit, which sends a page to that person.
The paging mechanism is done via Verizon Wireless's webpage www.myairmail.com (my company has a contract with them). When the user clicks submit, it forwards the request to this website (via action=""). However, a confirmation page from Verizon is then displayed in this frame, which I'd like to instead put a personalized confirmation page.
Is there a way to forward from a servlet to an outside URL, or am I pretty much stuck with what I've got?
Thanks
Jason
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

Maybe you could use HttpURLConnection to submit the page and then parse the returned content for status messages then redirect to your own custom page.
Junilu
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

I would also look through the source code for test frameworks like HttpUnit for clues (I think its on SourceForge but there's definitely a link to it from http://www.JUnit.org ).
Junilu
Christopher Dixon
Greenhorn

Joined: Jan 30, 2002
Posts: 22
You may also find some tag libraries provide the functionality you're looking for. Check out the Jakarta Standard taglibs project, specifically the IO taglibor the Scrape taglib
Both encapsulate a call to another URL outside the web application quite nicely.
HTH,
Chris
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

I don't think you are trying to forward - that would imply that the user is leaving your website. What you are actually trying to do is invoke someone else's webapp as a subroutine of your own web logic.
As Junilu said, the servlet can use HttpURLConnection for that, just like applets do (except that you don't have the "sandbox" restriction that applets have).
The only special considerations would be to allow for the extra time it takes to do a request to someone else's network (user's browser could time out) - and, of course, the fact that the external server might sometimes return an unexpected response.


Customer surveys are for companies who didn't pay proper attention to begin with.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
What you said is right Tim, they have a CGI script that runs on the request, that's mainly what I was trying to get.
But I've decided to go another route. Since this webapp ties in with a bigger application that listens to a database for updates, I still have to come up with a way for that listener to page people when an event occurs. So I decided to dig into the javax.comm API and go that route instead, avoiding the whole Verizon webpage thing.
Thanks for the info and the links though, will come in very handy when I start learning the net API's.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: forwarding to an outside URL
 
Similar Threads
Displaying confirmation window using servlets
hiding URL address with a fake one
Page not found
page forward
How to access resource outside ServletContext