【问题标题】:Simple html form.. action field not being executed简单的 html 表单.. 未执行的操作字段
【发布时间】:2014-01-06 21:18:47
【问题描述】:

我有一个简单的 html 表单(名字和姓氏),一旦我点击提交,它应该会给我一个来自我的 java servlet 的简单响应,上面写着“Hello plus first name plus last name”

我使用 eclipse 和一个 tomcat 插件运行它,它运行良好.. 但是当我创建一个 war 文件并从 tomcat 部署它时.. 我得到第一个屏幕.. 输入名字和姓氏.. 但是当我点击提交,它会在我的代码中寻找“WelcomeScreen” 我没有“welcomeScreen” 下面是我的 HTML 代码。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Please enter your name</title>
</head>
<body>
    <form name="input" action=Hello method="get">
        First name: <input type="text" name="firstname"><br> Last
        name: <input type="text" name="lastname"> <input type="submit"
            value="Submit">
    </form>
</body>
</html>

【问题讨论】:

  • 如果是拼写错误,请在Hello 周围加上引号来纠正它。
  • 我的错误..我不小心遗漏了到目前为止我尝试过的内容...我尝试将我在操作字段中的内容替换为...“你好”甚至尝试输入@987654321 @并且它仍然没有工作..在eclipse上当我这样做时..填写表格,提交它,它应该进入下一页/servlet或者你说它应该去的任何内容..适用于eclipse..但是不是当我从tomcat(终端)部署和运行它时

标签: java html tomcat servlets action


【解决方案1】:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Please enter your name</title>
</head>
<body>
    <form name="input" action="Hello.html" method="get">
        First name: <input type="text" name="firstname" /><br> 
        Last name: <input type="text" name="lastname" />
        <input type="submit" value="Submit" />
    </form>
</body>
</html>

我写了正确的代码。 html中有一些错误喜欢;

<form name="input" action=Hello method="get"> 
<!-- You've forgotten quotes -->
<!-- And also dont forget to write ".html" or Hello controller in framework like MVC -->
<form name="input" action="Hello.html" method="get">

另一个

<input type="text" name="firstname">
<!-- You've forgotten /// -->
<input type="text" name="firstname" />

还有你的 Hello.html

<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <script type="text/javascript">
        var get = window.location.search.replace( "?", "" );
        alert(get);
    </script>
</head>
<body>
    <div>Content</div>
</body>
</html>

【讨论】:

  • 工作就像一个魅力。感谢您的快速帮助!
猜你喜欢
  • 1970-01-01
  • 2013-05-20
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 2014-03-18
  • 2016-11-15
  • 2016-12-25
  • 2011-02-05
相关资源
最近更新 更多