samedi 25 novembre 2017

Error validating DNI in Java Web

I created a Java Web application connected to a GlassFish server and i have an error that i can't resolve. My app is that if a dni (nif) is valid or not. First I put a formulary thatsends the dni to the validator and determines if it is valid. OK, all seems good but when I run the file, pass this:

The error

I think that the problem is the import but i'm not safe...help please. thanks

<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
   <head>
      <title>Validate dni</title>
   </head>
   
   <body>
       <form action = "DNIvalid.jsp" method = "GET">
         Input your DNI: <input type = "text" name ="dni">
         <input type = "submit" value = "Submit" />      
      </form>
 <% Pattern pattern=Pattern.compile("(\\d{1,8})([TRWAGMYFPDXBNJZSQVHLCKEtrwagmyfpdxbnjzsqvhlcke])");

        Matcher matcher=pattern.matcher(request.getParameter("dni"));

        if(matcher.matches()){

            String letra=matcher.group(2);

            String letras="TRWAGMYFPDXBNJZSQVHLCKE";

            int index=Integer.parseInt(matcher.group(1));

            index=index%23;

            String reference=letras.substring(index,index+1);

            if(reference.equalsIgnoreCase(letra)){

            
                out.println("Is valid");

            }else{

             
                out.println("Is invalid");
            }

        }else{

      
            out.println("Is invalid");
        } %>
   



Aucun commentaire:

Enregistrer un commentaire