Invalid HTML tag location

I am trying to make a simple form using HTML and servlets. Everything is installed, but I get a yellow underline in my HTML markup. He says: Invalid tag location (input), where I am trying to implement a form in my HTML.

My code looks good and I see no problem. What am I doing wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/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> 
+5
source share
1 answer

The form tag can only contain block elements — this is XHTML Strict, so neither <span> nor <input> are valid. You can wrap it in a <div> , but that's fine.

For instance:

 <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 (for example, IE8 does not support it at all, and, unfortunately, some people still have to use it). You must use HTML5, it also has XML serialization.

+4
source

Source: https://habr.com/ru/post/1212783/


All Articles