Good I have a jsp that passes data to my servlet with ajax.
This is my Script
$(document).ready(function() {
var dni = "00000r";
$.post('actionServlet', {
}, function(responseText) {
num: "1"
$('#datos').html(responseText);
});
$("#mostrar").click(function(){
$.post('actionServlet', {
num: "2",
dni: dni
}, function(responseText) {
$('#datos').html(responseText);
});
});
});
and this my java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType( "text/html; charset=iso-8859-1" );
PrintWriter out = response.getWriter();
// Obtengo los datos de la peticion
String numero = request.getParameter("num");
String nombre = request.getParameter("nombre");
System.out.println(numero+" "+numero.getClass());
if(numero == "1"){
out.println("Prueba numero 1");
}
if(numero == "2"){
out.println("Ha funcionado");
}
}
Passing the data does not make me if in the java. Any solution? Thank you very much in advance