Servlets and web components
In this section, we begin the study of web components present in Java EE 7 and supported by WildFly 10, starting from the servlets. Let's start with a simple example of a servlet:
@WebServlet("/SimpleServlet") public class SimpleServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("my GET"); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("my POST"); } }
This servlet represents two HTTP methods, GET and POST, represented by the doGet and doPost methods inherited by the javax.servlet.http.HttpServlet abstract class.
Note
More information on the HTTP methods can be seen in Chapter 6, Creating REST Services, in the REST and HTTP paragraph.
According to the chosen HTTP method...