This might be very simple one but i am not understanding where i am doing wrong. I have a form which has three links, namely LogIn,SignUp and ForgotPassword. I used javascript document..action to set action for these links using a simple switch case. while Singup and ForgotPassword refer to singup.jsp and ForgotPassword.jsp respectively, LogIn link refers to a servlet. And i used url-pattern given in web.xml file as its target. when i run it gives error upon clicking on sigin. Any idea what's going wrong?
<script type="text/javascript">
function redirect(tid)
{
switch(tid)开发者_如何学运维
{
case "a":
{
if(document.form.Username.value=='')
{
alert("Enter your username");
return false;
}
if(document.form.Password.value=='')
{
alert("Enter your password");
return false;
}
document.form.action="check" //check is the urlpattern defined for checkUser servlet
}
break;
case "b":
document.form.action="Signup.jsp"
break;
case "c":
document.form.action="Forgotpassword.jsp"
break;
}
}
</script>
Try this:
document.forms[0].action = 'Forgotpassword.jsp';
As per the comment on the question:
The error is HTTP POST method is not supported by this URL
The servlet which is listening on the URL does not have the doPost()
method overridden. Apparently you're using a <form method="post">
to submit to a servlet which has only doGet()
implemented. You need to rename the doGet()
method to doPost()
.
Please note that this has nothing to do with the JavaScript code which you posted in the question.
精彩评论