简单的html表单..动作字段未被执行

时间:2014-01-06 21:18:47

标签: java html tomcat servlets action

我有一个简单的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>

1 个答案:

答案 0 :(得分:0)

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