最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Invalid location of HTML tag - Stack Overflow

programmeradmin1浏览0评论

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
 |  Show 2 more ments

1 Answer 1

Reset to default 4

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

发布评论

评论列表(0)

  1. 暂无评论