I'm starting with Java Servlets doing a program with a login. I'm fine but when I click on the Login button I get this error
java.lang.NumberFormatException: null java.lang.Integer.parseInt (Integer.java:542) java.lang.Integer.parseInt (Integer.java:615) servlets.Login.doPost (Login.java:57) javax.servlet.http.HttpServlet.service (HttpServlet.java:650) javax.servlet.http.HttpServlet.service (HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
I know it has to do with line 57 but I can not understand what is wrong. This is the servlet login code
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int n= Integer.parseInt(request.getParameter("Cedula"));
String p=request.getParameter("Contraseña");
if(metodos.Validate.checkUser(n, p)) {
RequestDispatcher rd=request.getRequestDispatcher("Welcome");
rd.forward(request,response);
} else {
out.print("Sorry username or password error");
RequestDispatcher rd=request.getRequestDispatcher("index.html");
rd.include(request,response);
}
out.close();
}
This is the method checkuser
public static boolean checkUser(int Cedula,String Contraseña) {
boolean existe=false;
try {
Conexion db=new Conexion();
Connection cn=db.Conectar();
Statement st=cn.createStatement();
PreparedStatement ps =cn.prepareStatement("select * from CLIENTE where Cedula=? and Contraseña=?");
String cedula = String.valueOf(Cedula);
ps.setString(1, cedula);
ps.setString(2, Contraseña);
ResultSet rs =ps.executeQuery();
if(rs.next()) {
existe = true;
/*
this.identificacion=rs.getInt("identificacion");
this.contraseña=rs.getString("contraseña");
cliente=true;
*/
} else {
existe = false;
}
} catch(Exception e) {
e.printStackTrace();
}
return false;
}
And this is my class Conexión
public class Conexion {
private String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String url="jdbc:sqlserver://localhost:1433;databaseName=HOTEL";
private String user="sa";
private String pass="progra";
public Conexion() {
}
public Connection Conectar() {
try {
Class.forName(driver);
return (DriverManager.getConnection(url,user,pass));
} catch (Exception e) {
}
return null;
}
public void Desconectar(Connection cn) {
try {
cn.close();
} catch (Exception e) {
}
}
}