I have a form on my .jsp page which sends a password back to the server.
<form name="login" action="j_security_check" method="post">
<input type="text" name="j_username">
<input type="password" name="j_password">
<input type="submit" name="Login"> </form>
I would like to do some processing on the j_password before processing it. Previously, I managed to do this by implementing a JavaScript through some processing codes by calling on a function that performs something similar to below:
<script type="text/javascript" src="sha256.js">
<script> function hash() { document.login.j_password.value = '@' +
sha256_digest(document.login.j_password.value); } </script>
...
...
<input type="submit" value="Login" onClick="hash()"> </form>
Now, I am trying to implement a similar feature but instead of using JavaScript, I am trying to use Java. The main aim of my .java is to load a public.key, take the j_password, perform encryption, and replacing the j_password with its encrypted form.
// RSA.java Pseudocode
1) Get string from textbox "j_password"
2) Load public key from public.key
3) Perform encryption on j_password with key
4) Load cipher to textbox "j_password"
However, most examples I see implement a "<% %>" calling but this gives me an impression that it would perform on page load, rather than on clicking the login button. I also noticed I could compile it as a .class with javac and load it as an "" but can this method be used to modify the input of j_password? While it is a .jsp and I can implement Java directly with "<% %>", I don't think it is acceptable in current JSP standards. Does anyone have any recommendations or ideas to point me in the right direction?
Thank you.