• Post Reply Bookmark Topic Watch Topic
  • New Topic

If a URL already points to a resource, can a servlet still be mapped by this URL?

 
Rui Yuan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a link with URL say "/atom/filename.link" on one webpage on my server. On clicking it, a response will return in XML format.

In the XML there is information like:

<library id = "123" path =""/>
<document id = "1234" path =""/>

With this information I can generate a URL to another link, say /libray?id=123/document?id=1234

Now I would like to realize a function so that on clicking this link, it will be automatically redirected to that new link, which is generated from the XML file.

At first I try to use a servlet/filter in a web-app and then deploy it on the server, inside this servlet/filter I make a new URL connection with the same request URL and retrieve the response and the parse the XML data. But now the request URL points to the servlet now, not the actual XML file.

For example, if I set the set the servlet-mapping to /atom, If I try to connect to the URL /atom/filename.link inside the servlet, will it still be directed to this servlet? It's like a loop, and the real content can never be reached because now the servlet occupies its path.

I'm not sure if I have understood it correctly. Could anyone help me clarify it?
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Let me see if I understand you correctly. You want the servlet/filter to redirect to the XML page directly. This means the URL will be ...xml at the end, right? Or you want the servlet to process/parse the XML file and display it accordingly?

If it is the latter, you should look into those XML API libraries. If it is the first you can simply do the response.sendRedirect(<your xml file>).

If you use forward instead, the URL will be your servlet name rather than the xml file name.
 
Rui Yuan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Welcome to the Ranch

Let me see if I understand you correctly. You want the servlet/filter to redirect to the XML page directly. This means the URL will be ...xml at the end, right? Or you want the servlet to process/parse the XML file and display it accordingly?

If it is the latter, you should look into those XML API libraries. If it is the first you can simply do the response.sendRedirect(<your xml file>).

If you use forward instead, the URL will be your servlet name rather than the xml file name.


Hi, thank you for your reply. It seems my original question is a bit confusing, so I modified it to make it clearer. I want the servlet to process the XML file, but the prerequisite is to GET this XML file under the URL /atom/.... which actually leads to the servlet.....
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should check out the JAXP Java tutorial.

There are many ways to read the XML file (eg SAX, DOM). I don't which one you prefer.

I once in a while need to read XML files in my projects and I chose DOM. And kept the same approach for all the xml file parsing.
 
Rui Yuan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Then you should check out the JAXP Java tutorial.

There are many ways to read the XML file (eg SAX, DOM). I don't which one you prefer.

I once in a while need to read XML files in my projects and I chose DOM. And kept the same approach for all the xml file parsing.


I think reading XML files is not that difficult...I would also use DOM in my case.

The difficulty here is how to get the XML file, because it's in a response from a URL. And now I can't get the response because the URL itself leads to the servlet, not the original resource.
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I see that can be a problem.

I don't know if this help but you can try seeing the headers have the original file or the request allow you to get the necessary info.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!