Hi, first of all, sorry for my english, but I´m having a problem and I can´t resolve it.
This is part of my jsp code:

<%
    if( session.getAttribute("usuario") == null )
        response.sendRedirect("index.jsp");
    ArrayList pacientes = new ArrayList();
    String mensaje="";
    String dni="", nombre="", apellido="", email="", sexo="", telefono="", fechanacimiento="", obrasocial="", codigo="";
    String accion= request.getParameter("accion");
    if(accion!=null){
        Connection conn = ConnectionManager.getConnection();

         if( accion.equals("agregar") ) {
            nombre = request.getParameter("nombre");
            apellido = request.getParameter("apellido");
            dni = request.getParameter("dni");
            email = request.getParameter("email");
            sexo = request.getParameter("sexo");
            telefono = request.getParameter("telefono");
            fechanacimiento = request.getParameter("fechanacimiento");
            obrasocial = request.getParameter("obrasocial");
            codigo = request.getParameter("codigo");
            
            Paciente p= new Paciente();
            p.setNombre(String.valueOf(nombre));
            p.setApellido(String.valueOf(apellido));
            p.setDni(Integer.parseInt(dni));
            p.setEmail(String.valueOf(email));
            p.setSexo(String.valueOf(sexo));
            p.setTelefono(Integer.parseInt(telefono));
            p.setFechanacimiento(Date.valueOf(fechanacimiento));
            p.setCodigo(Integer.parseInt(codigo));
            p.setObrasocial(String.valueOf(obrasocial));
            p.insertar(conn);
            mensaje = "<I>El registro ha sido insertado</I>";

            dni=""; nombre=""; apellido=""; email=""; sexo=""; 
        }
    }
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Pacientes</title>
    </head>
    <body>
        <jsp:include page="encabezado.jsp" />
        <h1>Pacientes</h1>
        <table width="100%" border="0">
            <tr>
            <form method="POST" action="paciente.jsp">
                <td><input type="text" placeholder="Nombre" name="nombre" /></td>
                <td><input type="text" placeholder="Apellido" name="apellido" /></td>
                <td><input type="text" placeholder="DNI" name="dni" maxlength="8" /></td>
                <td><input type="text" placeholder="Email" maxlength="35" size="30" name="email" /></td>
                <td><input type="text" placeholder="Telefono" maxlength="35" size="30" name="telefono" /></td>
                <td><input type="text" placeholder="AAAA-MM-DD" maxlegth="10" size="12" name="fechanacimiento" />
                </td>
                <td>
                    <input type="radio" name="sexo" value="hombre" />Hombre
                    <input type="radio" name="sexo" value="mujer" />Mujer
                </td>
           </tr>
            <tr>
                <td><input type="text" name="" placeholder="Obra Social" /></td>
                <td><input type="text" name="" placeholder="Código de socio" /></td>            
                <td><input type="submit" value="Agregar" name="agregar" />
                    <input type="hidden" value="agregar" name="accion" />
                </td>
                </form>
            </tr>
        </table>

And when I submit it, it says.

org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /paciente.jsp en línea 66

63:             p.setSexo(String.valueOf(sexo));
64:             p.setTelefono(Integer.parseInt(telefono));
65:             p.setFechanacimiento(Date.valueOf(fechanacimiento));
66:             p.setCodigo(Integer.parseInt(codigo));
67:             p.setObrasocial(String.valueOf(obrasocial));
68:             //p.setFechanacimiento(Date.valueOf(String.valueOf(fechanacimientoo)));
69:             p.insertar(conn);


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

causa raíz

java.lang.NumberFormatException: null
	java.lang.Integer.parseInt(Integer.java:417)
	java.lang.Integer.parseInt(Integer.java:499)
	org.apache.jsp.paciente_jsp._jspService(paciente_jsp.java:121)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

I tried printing the input value from dni and it returns null but it doesnt happen for name, or any other string value. Please help me, thanks.

First of all remove all of the database code and put it in seperate methods and classes and call those methods from the jsp.

Then read the exception that you get. It tells you exactly what the error is at line 66
The NumberFormatException is thrown when you cannot convert something to a number:
Integer.parseInt(codigo)
And the stacktrace says: java.lang.NumberFormatException: null

You are trying to write some complex code with out knowing the basics. Handling NumberFormatException and figuring out that you are trying to parse something which is null is very simple. Especially since the exception tells you exactly that. I would like to suggest that you to take one step back.

Forget about jsps and jasper. Try to write simpler codes first and make a lot of mistakes. Seriously that is how you learn to read the stack trace and correct the errors that you get. By making them.

And by trying to execute queries in jsp is an indication that you haven't written many java core programs. Did you always put all of your code in the main method? Or did you have different classes with methods and call those methods in the main. You must do the same here. NO java code in the jsp unless they are used to displying the data or retrieve them and pass them as arguments to methods that do all the work

commented: 0 +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.