Servlets / How can we discard a request?

C

Covington Bradshaw

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
 
D

Daniel Pitts

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?
 
L

Luc The Perverse

Daniel Pitts said:
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
 
M

Mark Space

Covington said:
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.
 
M

Mike Schilling

Covington Bradshaw said:
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.
 
C

Chris Uppal

Daniel said:
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
 
I

Ian Wilson

Daniel said:
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
 
C

Chris Uppal

Ian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top