[英]Unable to include css and JS files in Liferay Portlet JSP Page
I have download a Jquery Image Slider source and want to integarte with my JSP File 我已经下载了一个Jquery Image Slider源代码,想要与我的JSP文件进行整合
This is my Folder Struture 这是我的Folder Struture
This is the way i am including them 这是我包括他们的方式
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link type="text/css" href="/css/jquery.ui.theme.css" rel="stylesheet" />
<link type="text/css" href="/css/jquery.ui.core.css" rel="stylesheet" />
<link type="text/css" href="/css/jquery.ui.slider.css" rel="stylesheet" />
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen"/>
I get this 404 in server console 我在服务器控制台中得到了这个404
20:50:04,625 WARN [404_jsp:109] /css/jquery.ui.theme.css
20:50:04,640 WARN [404_jsp:109] /css/jquery.ui.core.css
20:50:04,640 WARN [404_jsp:109] /css/jquery.ui.slider.css
20:50:04,656 WARN [404_jsp:109] /css/style.css
20:50:04,671 WARN [404_jsp:109] /js/cufon-yui.js
20:50:04,671 WARN [404_jsp:109] /js/GreyscaleBasic.font.js
20:50:04,687 WARN [404_jsp:109] /js/jquery.easing.1.3.js
Put the links in liferay-portlet.xml
and let Liferay load the css and javascript. 将链接放在
liferay-portlet.xml
,让Liferay加载css和javascript。 That is the better way (eg if user wants put two portlets to one page). 这是更好的方法(例如,如果用户想要将两个portlet放到一个页面上)。
liferay-portlet.xml: Liferay的-portlet.xml中:
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
And Olaf is right, you must move the css- and js-folders (and images too) from WEB-INF
to docroot
folder 而且Olaf是对的,你必须将css-和js-folders(以及图像)从
WEB-INF
到docroot
文件夹
Several issues: 几个问题:
If you create docroot/css and docroot/js, you will still get 404, because you can't find the files on /css/style.css, but in /your-portlet/css/style.css - the generic way to address it in jsps is 如果您创建docroot / css和docroot / js,您仍然会得到404,因为您无法在/css/style.css上找到文件,但在/your-portlet/css/style.css中 - 这是通用的方式在jsps中解决它
< link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css"/>
Late Edit: request
on a portlet's JSP doesn't always work, because according to the JSP specification it's a HttpServletRequest. 延迟编辑:对portlet的JSP的
request
并不总是有效,因为根据JSP规范,它是一个HttpServletRequest。 In the portal world, this is not often relative to the current path of your portlet. 在门户网站中,这通常与您的portlet的当前路径无关。 Thus, I'd recommend to go with Mark's answer rather than mine: liferay-portlet.xml contains files relative to the current portlet.
因此,我建议使用Mark的答案而不是我的答案:liferay-portlet.xml包含与当前portlet相关的文件。 Since Liferay 7.0, you may use an OSGi-Component's equivalent to liferay-portlet.xml.
从Liferay 7.0开始,您可以使用OSGi-Component等效于liferay-portlet.xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.