admin管理员组文章数量:1326327
I am trying to make a simple form using HTML and Servlets. Everything is set, but I am getting a yellow underline in my HTML markup. It says: Invalid location of tag (input) , where I am trying to implement the form in my HTML.
My code looks good and I don't see the problem. What am I doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Projektuppgift1</title>
</head>
<body>
...
// This is where I am getting the error
<form action="LoginServlet" method="post">
username: <input type="text" name="name" />
password: <input type="password" name="password" />
<input type="submit" value="submit" />
</form>
...
</body>
</html>
I am trying to make a simple form using HTML and Servlets. Everything is set, but I am getting a yellow underline in my HTML markup. It says: Invalid location of tag (input) , where I am trying to implement the form in my HTML.
My code looks good and I don't see the problem. What am I doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Projektuppgift1</title>
</head>
<body>
...
// This is where I am getting the error
<form action="LoginServlet" method="post">
username: <input type="text" name="name" />
password: <input type="password" name="password" />
<input type="submit" value="submit" />
</form>
...
</body>
</html>
Share
Improve this question
edited Feb 6, 2015 at 9:23
meskobalazs
16.1k2 gold badges43 silver badges63 bronze badges
asked Feb 6, 2015 at 9:06
SmileSmile
511 gold badge2 silver badges11 bronze badges
7
- 3 Just to be sure. Is this part after </head> tag in <body>, </body> tags? – egellon Commented Feb 6, 2015 at 9:09
- body tag and closing html tag is missing^^, Tip: for clean html also use <label for="name">username:</label> for your inputs... – mondjunge Commented Feb 6, 2015 at 9:11
- Anyway, why are you using xhtml strict? Nobody ever really used it (beside fefe) and its html5 in 2015... build code for the future, not for yesterday... – mondjunge Commented Feb 6, 2015 at 9:17
- I think he uses it because it is the default for JSP, as it heavily relies on XML. (Still a bad idea though) – meskobalazs Commented Feb 6, 2015 at 9:19
- oh, I did not see the jsp tag. Should upgrade to JSF 2.2 to have html5 support then and use ponents instead of plain html. – mondjunge Commented Feb 6, 2015 at 9:23
1 Answer
Reset to default 4The form
tag may only contain block elements is XHTML Strict, so neither <span>
nor <input>
is valid. You can wrap it in a <div>
though, then it is fine.
For example:
<form action="LoginServlet" method="post">
<div>Username: <input type="text" name="name" /></div>
<div>Password: <input type="password" name="password" /></div>
<div><input type="submit" value="submit" /></div>
</form>
However I would advise against using XHTML, it is a thing of the past, and has some serious drawbacks too (e.g. IE8 does not support it at all, and unfortunately some people still have to use this). You should use HTML5, it also has an XML serialization.
本文标签: javaInvalid location of HTML tagStack Overflow
版权声明:本文标题:java - Invalid location of HTML tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742202162a2432163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论