File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Response Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Response Header" Watch "Response Header" New topic
Author

Response Header

Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Hello
I want to know whether a requested resource is there or not on my server.
When a user send a request for a resource I need a mechanism on server to know whether it is there or not.

Thanks in Advance
Prabhakar
Lanka Prasad
Greenhorn

Joined: Nov 14, 2004
Posts: 21
You can use HEAD instead of GET for a foreign URL. This will return header info with out body.

-Lanka


SCJP 1.4
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Did you got what I asked for.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Prabhakar Rao:
Did you got what I asked for.


Probably not.
Why don't you try to explain a little more fully.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Sure
Let assume that I am having a website.
I want to use Filters to customise the site.
In these Filters i want to know whether a resource requested for is available or not.
Suppose you type a bad url to my site I want to check for resource in the filter then pop appropriate message.

Hope you got the problem.
-Prabhakar
Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
I didn't get you. Why you want to check in filters whether the resource is available or not.
you just follow the asusual flow and if resource is not available , direct it to specific page with message.

As I m not able to think the benefit of checking resource availability in filters.


Chop your own wood, and it will warm you twice. - Henry Ford
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Containers do this for you.
If you want to show your own page, just add your own custom 404 error page.
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Thanks I know that error page mechanism was there.
But i need to know it programmatically.
Prabhakar Rao
Ranch Hand

Joined: Aug 23, 2006
Posts: 40
Hai
I want to know is there any mechanism for knowing whether a resource is there or not on the server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

Firstly, patience is a virtue.

Secondly, think about for a minute. If the request is going to result in a 404, any filters would never be invoked. So how could you test for it?

The web.xml mechanisms are there for a reason.

If you want to test outside the bounds of a request to that resource, that's another story...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes and no.
You find out that something is not there when you try to access it and it fails. At that point the spec provides a way to handle this gracefully.

What you're describing sounds like it would genenerate two reads for every request. One to see if the file is there and then another to actually serve up the file/resource.

Also, all resources are not files on the system, requests can also be made for url-mappings to servlets, etc...
 
 
subject: Response Header