JavaScript 和 Jsp 页面
这可能非常简单,但我不明白我做错了什么。我有一个包含三个链接的表单,即登录、注册和忘记密码。我使用 javascript document..action 使用简单的 switch case 来设置这些链接的操作。 Singup 和 ForgotPassword 分别引用 singup.jsp 和 ForgotPassword.jsp,而 LogIn 链接引用 servlet。我使用 web.xml 文件中给出的 url-pattern 作为其目标。当我运行时,单击登录时会出现错误。知道出了什么问题吗?
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
根据对该问题的评论:
正在侦听该 URL 的 servlet 没有覆盖
doPost()
方法。显然,您正在使用请注意,这与您在问题中发布的 JavaScript 代码无关。
As per the comment on the question:
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 onlydoGet()
implemented. You need to rename thedoGet()
method todoPost()
.Please note that this has nothing to do with the JavaScript code which you posted in the question.