friends using the method .POST
of jquery
send some parameters to a servlet mapped with spring
, after that I need to return a value to the view, for this I transform the String
to JSON
with the library GSON
, but when I return that value I skip that error 400 (bad request), which could be doing wrong? Here I leave the code
Javascript file:
function sesion(){
console.log('inicio de envio de parametros a servlet');
formulario = $('#formBus');
$.post('ConsultasRms/autenticar.html',formulario.serialize(),function (data,status){
console.log('entro a función de sesión data: '+data+' estatus: '+status);
$("#res").html(data);
}),"JSON";
servlet:
@RequestMapping("/autenticar")
public String login(HttpServletRequest request, HttpServletResponse response,
@RequestParam("j_username") String user,
@RequestParam("j_password") String pass
) throws Exception {
logger.info("Inicio de metodo login con paramatros usuario: "+user+" y pass: "+pass);
System.out.println("Inicio de metodo login con paramatros usuario: "+user+" y pass: "+pass);
String direccion = "index.jsp";
Gson gson = new Gson();
String retorno = gson.toJson(direccion);
// FacesContext context = FacesContext.getCurrentInstance();
// request = (HttpServletRequest) context.getExternalContext().getRequest();
if(user.contains("prueba") && pass.contains("1234")){
System.out.println("autenticado, retorno json: "+retorno);
return retorno;
}
return null;
}
}