gpt4 book ai didi

java - JSF 2 :How include style sheets and javascript?

转载 作者:行者123 更新时间:2023-12-01 15:47:32 24 4
gpt4 key购买 nike

我遇到了一个奇怪的问题,如果我的页面index.xhml是:

<html   xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">

<head>
//.. import css and javascript
</head>
<body>
// .. my page content
</body>
</html>

一切都好,但是,如果我更改为<head><h:head><body></h:body>我的页面似乎没有很好地应用该样式,据我所知,我的 javascript 文件似乎没有在页面中应用。为什么会出现这种情况?我已经尝试更改为 <h:outputScript library="javascript" name="file.js" />但它也不起作用。

有什么想法吗?为什么会发生这种情况?

最佳答案

使用上面的主体,然后你可以直接在你的jsp中使用这些方法

<script src="${pageContext.request.contextPath}/yourJSFile.js" type="text/javascript"/>

<link rel="stylesheet" href="${pageContext.request.contextPath}/yourCSSFile.css" type="text/css" />

yourJS.js yourCSS.css 文件应该位于您的 WebContent(${pageContext.request.contextPath}) 下。最好为你的 js、css、页面等维护单独的文件夹。

关于java - JSF 2 :How include style sheets and javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6849041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com