I understand that Rest is an architecture between a server and a client, httpRequest and httpResponse, it is the topic that we are seeing in a course that I am doing. The problem is that I'm doing in Rest a code that inserts data through parameters @FormParam in a database, which works excellent, however, once the data is sent I want it to be redirected to another page, for example the start but here my question comes, in my course they say no, I have to do something with html or javascript and the client makes decisions, I do not really understand that, I am so used to the servlets and the RequestDispatcher and redirect me that this I do not understand part of it.
I have followed recommendations like using URi or httpResponse.sendRelocation (); but they say it goes against the philosophy of REST.
I leave my code for you to see, I'm really stuck by the habit of redirection, how do I apply what they say the client makes decisions ???. As you will see the method Returns a String, however I thought about changing the method by a Response, but is that logical? Is that practice that I want to do in Rest wrong? What is the client making decisions? and how do I apply it?
package aeropuerto_empleados;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import data_access_object.ConexionAeropuerto;
//Acá tengo que poner algún path? porque me está tirando error http 404
public class Administradores {
@POST
@Produces(MediaType.TEXT_HTML)
@Path("/administradores")
public String insertarEmpleado(@FormParam("nombre") String nombre , @FormParam("apellido") String apellido, @FormParam("usuario") String usuario, @FormParam("pass") String pass, @FormParam("email") String email, @FormParam("direccion") String direccion){
try
{
ConexionAeropuerto c= new ConexionAeropuerto();
Connection con= c.connectarAhora();
if(con!=null)
{
Statement st;
st=con.createStatement();
st.executeUpdate("INSERT INTO administradores(nombre,apellido,usuario,pass,email,direccion) VALUES('"+nombre+"','"+apellido+"','"+usuario+"','"+pass+"','"+email+"','"+direccion+"')");
st.close();
System.out.println("Funciona el try and catch");
//Qué codigo puedo escribir acá para que me redireccione al index.jsp una vez realizada la consulta??? debe ser simple imagino.
//Response.getRequestDispatcher("index.jsp").forward(request, response);
}
else
{
System.out.println("Algo Salió mal no se pudo insertar los datos");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
return "<html>" + "<body><h3>" + "El nombre del empleado es: " + usuario + direccion + "<br>"+ "El apellido del empleado es: " + pass + "</h3></body>" + "</html>";
}
}