How can a servlet always perform the same task?
- by membersound
I want a Servlet to perform always the same tasks. Regardless of if it is a GET or POST.
At the moment I just call the doGet() from doPost(), which works fine.
Then I tried overriding the service() method, and I thought it would just work the same way. But it does not!
The code somehow gets executed, but the response does not generate the webpage:
response.getWriter();
response.println(string);
This code works for the doGet/doPost methods, but not for the service. Why?
Servlet:
class MyWebServlet extends HttpServlet {
@Override
public void service(ServletRequest request, ServletResponse response) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String string = "teststring";
out.println(string);
}
}