Jspx files and conditional comments

亡梦爱人 提交于 2019-11-29 21:30:20

问题


I'd like to create a web application using Spring and .jspx web pages.

My question is how can I put conditional commentaries for IE in jspx? They seem to be not interpreted.

<!--[if lt IE 9]>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

Also I would like my web pages to be HTML5 compliants.

I've tried some methods but I got incompatibilty issues in IE9 (seems to not recognize header and section).

Edit:

Here is my head tag

<meta content="text/html" charset="UTF-8" http-equiv="content-type" />
<link rel="stylesheet" type="text/css" href="css/style.css" />  
<!--[if lte IE 9]>
<link rel="stylesheet" type="text/css" href="css/style_IE8.css" />
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

But, if I look at the source under IE9 I don't see the links to html5shiv and my secondary css.


回答1:


According to the JSP 2.0 specification, section 1.5.2, comments in jsp documents are ignored:

Comments in JSP documents use the XML syntax, as follows:

<!-- comments ... ->

The body of the content is ignored completely. Comments in JSP documents may be used for documentation purposes and for “commenting out” portions of a JSP page.

Section 6.2.2 shows an example using jsp:text and CDATA sections which could be adapted to your usecase, please try if the following code works:

<jsp:text><![CDATA[<!--[if lte IE 9]>]]></jsp:text>
...
<jsp:text><![CDATA[<![endif]-->]]></jsp:text>



回答2:


After a vast quantity of attempts, I found that using ASCII codes for the comment symbols worked very nicely on .jspx pages. Try this bit of code:

&lt;&#33;&#45;&#45;[if IE]>

    <link rel="stylesheet" type="text/css" href="css/screenIE.css" />

&lt;&#33;[endif]-->



回答3:


For HTML 5 compatibility using the htmlshiv imports are correct. Make sure you have the conditional imports inside the head tags. This has nothing to do with jstl.

    <head>
    //Other imports
    <!--[if lt IE 9]>
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>



回答4:


Well, if you view the generated HTML, you will realize, that jstl will escape the stuff out in the conditional comment, so it will not work:

<!--[if IE 9]&gt;&lt;div id=&quot;ie-9&quot;&gt;&lt;![endif]-->

So Abhi, you need to tell jstl to leave the conditional part alone, tell it to don't parse it. Jstl will not ignore it, just because you've put it in the .



来源:https://stackoverflow.com/questions/8969854/jspx-files-and-conditional-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!