How can I POST paramters via JavaScript to Java Servlet?
Here is my html code, which works:
<div id="loginPanel">
<form action="/login" method="POST" class="form">
<label>Login:</label>
<input type="text" name="login" id="login">
<label>Password:</label>
<input type="text" name="password" id="password">
<div id="loginLower">
<input type="checkbox"><label memory="memory">Remember me</label>
<input type="submit" value="Login">
</div>
</form>
</div>
And now, I want to hash password and POST to /login hashPassword with something like this:
<form onsubmit="post()">
<label>Login:</label>
<input type="text" name="login" id="login">
<label>Password:</label>
<input type="text" name="password" id="password">
<div id="loginLower">
<input type="checkbox"><label memory="memory">Remember me</label>
<input type="submit" value="Login">
</div>
</form>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>
<script>
function post(){
var passhash = CryptoJS.MD5(document.getElementById("password").value);
//post to /login login and passhash
}
</script>
I'd tried to use AJAX, JQuery but those solutions has problems with /login, because they call localhost:8080/?login in browser while I want to call Java Servlet: web.xml
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>pl./*...*/.LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login/*</url-pattern>
</servlet-mapping>