【问题标题】:Javascript and Jsp pageJavascript 和 Jsp 页面
【发布时间】:2011-04-19 13:28:34
【问题描述】:

这可能非常简单,但我不明白我在哪里做错了。我有一个包含三个链接的表单,即 LogIn、SignUp 和 ForgotPassword。我使用 javascript document..action 使用简单的 switch 案例为这些链接设置操作。 Singup 和 ForgotPassword 分别指的是 singup.jsp 和 ForgotPassword.jsp,而 LogIn 链接指的是一个 servlet。我使用 web.xml 文件中给出的 url-pattern 作为目标。当我运行时,单击 sigin 时会出错。知道出了什么问题吗?

<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>

【问题讨论】:

  • 你能给我们看一些相关的源代码吗?否则很难说到底出了什么问题。
  • 请参考贴出的代码
  • 错误是这个 URL 不支持 HTTP POST 方法

标签: javascript jsp servlets


【解决方案1】:

试试这个:

document.forms[0].action = 'Forgotpassword.jsp';

【讨论】:

    【解决方案2】:

    根据对问题的评论:

    错误是此 URL 不支持 HTTP POST 方法

    正在侦听 URL 的 servlet 没有覆盖 doPost() 方法。显然您正在使用&lt;form method="post"&gt; 提交到仅实现doGet() 的servlet。您需要将doGet() 方法重命名为doPost()

    请注意,这与您在问题中发布的 JavaScript 代码无关

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多