My question comes from this code.
In short, it does:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
out.println("<html>");
out.println("<head>");
out.println("<title>Hi World</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1> Hello World </h1>");
doPost(request,response); // <<--- ???
out.println("</body>");
out.println("</html>");
}
finally
{
out.close();
}
}
I know it is just a sample code. But in the case I'm a newbie and make this "doPost inside a doGet stuff because I read it on SO and I think it is ok": what are the problems with doing this? is it ineficient (hitting the server twice for a no good reason)? fires unnecessary requests on the server? too much unnecesary code (for both the doPost and doGet methods)? is it utterly nonsense? or, maybe, there are scenarios when doing this is reasonable?