Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct syntax for a servlet that doesn't "return anything"?

What is the correct way of terminating a servlet that doesn't return any data to the client?

The purpose of the servlet in question is to recive some data from an Ajax request and fire off a TCP message to a piece of hardware to tell it to change it's state.

Do you have to specify a response at all?

I've opted for getting a reference to the Output stream and closing it, is this correct?

Should I send back a "hey that worked" message?

like image 512
Omar Kooheji Avatar asked Nov 06 '25 08:11

Omar Kooheji


1 Answers

If you just want to provide a "success" status just return HTTP code 200. You don't have to return any stream since you just want to say "OK".

public void doGet(...) {
    response.setStatus(HttpServletResponse.SC_OK); 
}
like image 123
adrian.tarau Avatar answered Nov 08 '25 00:11

adrian.tarau