Cómo escribir un ejemplo sencillo de front-end y back-end web en Java
la clase pública AddDeviceServlet extiende HttpServlet {
privada estática final larga serialVersionUID = 1L;
@Override
doGet vacío protegido (solicitud HttpServletRequest , respuesta HttpServletResponse) arroja ServletException, IOException {
doPost(solicitud, respuesta);
}
public void doPost(solicitud HttpServletRequest, respuesta HttpServletResponse) arroja ServletException , IOException {
String licenciaPlate = request.getParameter("licensePlate"); //Obtener el número de matrícula
String tel = request.getParameter("tel"); Obtenga el número de teléfono móvil.
MyDevice device = new MyDevice(licensePlate, tel); //Encapsule los parámetros de la solicitud en un objeto
save(device);
response.getWriter().print(true); //Devuelve un ID de éxito al cliente
response.setContentType("text/html; charset=utf-8") ;
response.setCharacterEncoding("utf-8");
response.getWriter().println("Su número de matrícula: "licencePlate); //Devuelve un ID de éxito; al cliente
response.getWriter().println("Su número de teléfono móvil: " tel //Devuelve una ID de éxito al cliente
}