Please note that the server code (Java) is executed before the client code (Javascript). One recommendation is to send the value from Javascript to the server. It will depend on the framework that you use the way. In jquery it would be:
Send data to a remote page:
$.ajax({
url: "ruta/al/controlador", //La dirección de tu controlador
method: 'POST', //El método, get o POST
data: {'firma': '11989798798'} //Los datos que enviarás al servidor
}).done(function() {
//Lo que harás luego que la función en el servidor se ejecute
alert( "firma verificada" );
});
It would only be necessary to capture the data on the server and that's it.
EDITED
Reference: In English .
The last code block of the question has the server part, you have to include the necessary library but it can help you more to build your solution.