• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get the URL of the page being redirected to?

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the URL of a servlet (XMLServletBuilder), which my login servlet (LoginServlet) has redirected to. The new page which the login page has redirected to is a servlet, which build a XML document.

//My login servlet
String login_servlet = "http://127.0.0.1/myApp/servlet/Login";

This login page redirects to a servlet which builds a XML document:

//XML builder
String xml_builder_servlet_URL = "http://127.0.0.1/myApp/servlet/XMLServletBuilder";

This "xml_builder_servlet" URL I need, when I want to parse the XML document being build.

...
org.jdom.input.SAXBuilder parser = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = parser.build( xml_builder_servlet_URL );
...

How can I get the page being redirected to from the login page?
 
Paul Clapham
Sheriff
Posts: 21114
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have the login page print the URL in the servlet log before redirecting.

But more seriously, who is this "I" that needs that? I assume that you personally don't need to find out, but there is some piece of code somewhere that may need to know it. How is this piece of code related to the login page, or to the page it redirects to? Is it running in the same servlet container, or is it somewhere else?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to allow the customers to access the invoice data in a big "shop" order system through XML files. I need to do some user authentification, where all login informations is stored in the database.

Then I could choose to 1) Make a login servlet which redirect to the XML page - the XML document where they can parse the data, or 2) Do the user authentification in each XML page by calling a java class.

I think that to print the redirect URL in a log file is a bad solution!

I didn�t thought it was a problem to get the URL from the page being redirected to?! I just hoped you could do something like:

...
java.net.URL url = new java.net.URL( loginUrl );
java.net.HttpURLConnection connection = ( java.net.HttpURLConnection ) url.openConnection();
... String redirectedURL = connection.getRedirectedURL();
[ December 21, 2005: Message edited by: Jeppe Fjord ]
 
Paul Clapham
Sheriff
Posts: 21114
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, let me try again. You have a login servlet (good idea) -- let's call it L -- and then you forward or redirect to a servlet that's going to do something with an XML document -- let's call it X. And X needs to know its own URL. Yes? But why does it need to know that? (If you redirect to X, then you can get X's URL from the request via its getRequestURL() method.)

Actually I am still confused. Your original post seems to say that X is going to pass itself to an XML parser. But that doesn't make sense to me either. It is going to pass some XML document to the parser, no?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have a login servlet (good idea) -- let's call it L -- and then you forward or redirect to a servlet that's going to do something with an XML document -- let's call it X. And X needs to know its own URL. Yes? But why does it need to know that?


No not correct! :-) X is the a servlet which build the XML document on the fly. The customer and other applications use a SAXParser file -- lets call this P -- to parse X. Before I can parse (with P) the XML document created by X, we need the URL of X, but we don�t request X, but instead the login servlet L, which redirect to X.

Here is the code of the parser file, P:


Does that help? :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic