简体   繁体   中英

Multiple <head> <body> tags in the jsp page

I have jsp page, that include multiple jsp pages. And in result i have multiple <head> <body> tags in the main jsp page. Everything is working, but I've read that multiple tags on one page not recomended.

So, is it any solution for merge all <head> <body> tags to one? And is it neccessary to merge?

I saw some related question there, but there it were solutions.

Thaks =)

只需从包含的jsps中删除重复的标签即可。

Everything is working, but I've read that multiple tags on one page not recommended.

It is "not recommended" to have multiple <head> or <body> elements because it is malformed HTML. It is only working because the web browsers you are testing against try to make sense of malformed HTML ... and in this case, they apparently succeed.

So, is it any solution for merge all <head> <body> tags to one?

There's no magic solution:

  • You could refactoring the included JSPs so that they are HTML fragments rather than self-contained pages. (In other words, remove the <head> and <body> tags from the included JSPs.)

  • You could implement some JSTL tags that can conditionally add the <head> and <body> elements depending depending on the context.

  • You could try using <iframe> elements rather than including the sub-pages into a "merged" page.

You need to be more careful / controlled with the jsp includes so that you don't end up with bad HTML, as you are getting now. While most browsers will accept poorly formed markup, it will cause you lots of problems down the road.

我想其他页面中包含的jsps不应包含<html>,<head>和<body>标记。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM