2

I'm getting a couple of weird warnings in a JSP file:

Invalid location of tag (h4)

Invalid location of tag (p)

Here's my code:

<!DOCTYPE html>
<html>
<head>
</head>
<body role="document">
    <div class="container container-white">
        <div class="list-group col-sm-12">
        <c:forEach var="recipe" items="${resultList}">
            <a href="<c:url value="/recipe/viewRecipe/${recipe.id}"/>" class="list-group-item">
                <h4 class="list-group-item-heading">${recipe.name}</h4>
                <p class="list-group-item-text">${recipe.description}</p>
            </a>
        </c:forEach>
        </div>
    </div>
</body>
</html>

I'm using STS 3.6.4 and would prefer not to turn off html validation since it has been helpful in other contexts, given my spotty html skills. The code above is virtually identical to the Bootstrap sample Custom Content. I saw some posts regarding blocking elements not being allowed within an <a> tag, but even the W3 site has a similar example:

    <aside class="advertising">
    <h1>Advertising</h1>
    <a href="http://ad.example.com/?adid=1929&amp;pubid=1422">
        <section>
            <h1>Mellblomatic 9000!</h1>
            <p>Turn all your widgets into mellbloms!</p>
            <p>Only $9.99 plus shipping and handling.</p>
        </section>
    </a> <a href="http://ad.example.com/?adid=375&amp;pubid=1422">
        <section>
            <h1>The Mellblom Browser</h1>
            <p>Web browsing at the speed of light.</p>
            <p>No other browser goes faster!</p>
        </section>
    </a>
</aside>

I tried adding the <section> tag to my code, but then I got the same invalid location warning on that tag.

Any ideas?

EDIT: I forgot to mention that the code as written does work correctly but I'd still like to get rid of the warnings, though, if possible. I've seen SO posts that mention Eclipse/STS JSP/HTML validation can be a bit flaky, but I haven't seen that in the 9 months I've been using it.

Community
  • 1
  • 1
LWK69
  • 1,070
  • 2
  • 14
  • 27

1 Answers1

0

Assuming you are using XHTML or HTML 4 (or lower), your anchor tags need to be located inside the header or paragraph tags. Anything else is invalid HTML. See the plethora of questions to get a better idea.

EDIT: Didn't read the question carefully enough. My guess is that you are using the wrong validator for JSP files. Go to Project > Properties > Web Content Settings and change the document type to HTML5.

Nielsvh
  • 1,151
  • 1
  • 18
  • 31
  • 1
    thanks for the tip. Unfortunately, adding that setting did not remove the errors. My jsp pages all have ` ` which should be HTML5 as far as I'm aware. It's not a big deal, just don't like seeing the warnings. – LWK69 Feb 28 '16 at 16:43
  • quick clarification - they are warnings, not errors. – LWK69 Feb 28 '16 at 16:49
  • Yes, but invalid HTML defaults browsers to quirks mode, where the rules are made up and style sheets don't matter. – Nielsvh Feb 29 '16 at 17:02
  • So, you're saying that even though these are just compile warnings they may end up being a problem when viewed in a browser? I've been testing with FF and Chrome and haven't seen any issues. I suppose IE, especially older versions, might be an issue? – LWK69 Feb 29 '16 at 17:21
  • Quirks mode used to be an issue because it doesn't follow any set rules across browsers. IE, FF, GC, etc have different rules for their quirks mode rendering and so what would look fine on FF would break in IE. This is why DOCTYPE should ALWAYS be included in your (x)HTML files and your pages should ALWAYS validate for that DOCTYPE. A little info can be found https://www.cs.tut.fi/~jkorpela/quirks-mode.html or http://stackoverflow.com/a/1695790/892327. – Nielsvh Mar 01 '16 at 20:52