> Hi,
> In a servlet filter or servlet, how can we discard a request?
> I.E. receive a given http request and simply decide to reject it
> without answering the client with any response.
>
> Thanks
Well, at the worst, you should return a 404 response. Its only polite.
If you don't want any response, why have a servlet at all?
Luc The Perverse - 10 Mar 2007 04:21 GMT
>> Hi,
>> In a servlet filter or servlet, how can we discard a request?
[quoted text clipped - 5 lines]
> Well, at the worst, you should return a 404 response. Its only polite.
> If you don't want any response, why have a servlet at all?
Well you could set it up in firewall rules - if you had a security concern
--
LTP
:)
Chris Uppal - 10 Mar 2007 16:36 GMT
> > Hi,
> > In a servlet filter or servlet, how can we discard a request?
[quoted text clipped - 3 lines]
> Well, at the worst, you should return a 404 response. Its only polite.
> If you don't want any response, why have a servlet at all?
Or one of the other 4xx or 5xx responses. I agree that it makes no sense not
to respond at all -- if there's a reason why the server doesn't want to service
this request then it should /say/ so.
And, anyway, if the server just drops the connection without sending a standard
HTTP response, then the client will almost certainly retry -- thus increasing
the load on your server...
-- chris
Ian Wilson - 12 Mar 2007 10:55 GMT
>> In a servlet filter or servlet, how can we discard a request?
>> I.E. receive a given http request and simply decide to reject it
>> without answering the client with any response.
>
> Well, at the worst, you should return a 404 response. Its only polite.
> If you don't want any response, why have a servlet at all?
I'd return whichever is the most appropriate of:
401 - unauthorised
402 - payment required
403 - forbidden
404 - not found
405 - method not allowed
406 - not acceptable (data type)
407 - proxy authentication required
408 - request time out
409 - conflict
410 - gone
411 - length required
412 - precondition failed
413 - request entity too large
414 - request too long
415 - unsupported media type
Chris Uppal - 12 Mar 2007 19:38 GMT
> I'd return whichever is the most appropriate of:
>
> 401 - unauthorised
[...]
> 415 - unsupported media type
Don't forget the 5xx seriese of response codes.
-- chris
> Hi,
> In a servlet filter or servlet, how can we discard a request?
> I.E. receive a given http request and simply decide to reject it
> without answering the client with any response.
>
> Thanks
Not sure, but can't you do this with filters? Filters have to chain,
iirc. Don't chain, the request gets discarded.
> Hi,
> In a servlet filter or servlet, how can we discard a request?
> I.E. receive a given http request and simply decide to reject it
> without answering the client with any response.
You don't have that much control. The servlet container will send a
response; all the servlet can do is determine its contents. By writing
nothing to the response's stream, you can make the body of the response
empty.