应用程序中未引用的JS文件 [英] JS files not referenced in the application

查看:100
本文介绍了应用程序中未引用的JS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jsp页面,其中正在调用我的xhtml页面.我将xhtml映射到facesServlet并激活了所有资源servlet,因此如果我点击xhtml页面,它将所有js和css文件都映射良好.

I have jsp page inside which am calling my xhtml page. Am mapping xhtml to facesServlet and have all resource servlet active so it maps all js and css file fine, if i hit xhtml page.

如果我打jsp页面,则这些文件未被引用,firebug会弹出各种js错误.

If I hit jsp page then those files are not referenced firebug pops out all sorts of js errors.

要变通,我将js和css文件添加到了Web文件夹中,并且在xhtml和jsp页面中包括并尝试了它们,但是这些文件尚未被引用,到目前为止,如果我直接点击xhmtl页面,则文件上传有效很好,但是如果我去打jsp页面,然后最终出现js错误,是否还有其他方法可以包含js文件.

To work around, i added js and css files to web folder and am including and tried them including in xhtml as well as jsp page but those are not referenced and as of now, if i directly hit xhmtl page then file upload works fine but if i go and hit jsp page then end up getting js errors, is there any other way of getting js file included.

这是引用我的js文件的方式

Here is how am referencing my js files

<%@ include file="/common/taglibs.inc" %>

<html>
<head>
    <link rel="stylesheet" href="/css/Main.css" type="text/css">
    <link rel="stylesheet" href="/css/Admin.css" type="text/css">
    <link rel="stylesheet" href="/css/Home.css" type="text/css">
    <script type="text/javascript" src="/js/icefaces/ace-jquery.js"/>
    <script type="text/javascript" src="/js/icefaces/ace-components.js"/>
    <script type="text/javascript" src="/js/icefaces/icepush.js"/>
    <script type="text/javascript" src="/js/icefaces/bridge.js"/>
    <script type="text/javascript" src="/js/icefaces/compat.js"/>
    <script type="text/javascript" src="/js/icefaces/fileEntry.js"/>
    <script type="text/javascript" src="/js/icefaces/jsf.js"/>
    <script type="text/javascript" src="/js/icefaces/icefaces-compat.js"/>


    <!-- BEGIN SCRIPT TO OPEN RIGHT NOW HELP POPUP, THIS SCRIPT INCLUDES THE FUNCTION OPENRN-->
    <
    %@ include file="/js/popupRightNow.inc" %>

    <!-- END SCRIPT TO OPEN RIGHT NOW HELP POPUP, THIS SCRIPT INCLUDES THE FUNCTION OPENRN-->

    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<jsp:include page="/navigation/TopNav.jsp" flush="true"/>

<jsp:include page="/trade_entry/UploadBlotter.xhtml"/>


<!--BEGIN BOTTOM NAV -->
<jsp:include page="/navigation/BottomNav.jsp" flush="true"/>
<!--END BOTTOM NAV -->
</body>
</html>

有什么想法和建议吗?

更新:

我需要使用jsf2创建新页面,并且已经创建了xhtml页面,但是我想获取我的应用程序headerfooter主题,这些主题已在jsp中定义,现在我尝试查找将jsp集成到xhtml中,但是正确地建议不要这样做.

I have requirement of creating new pages using jsf2 and i have created xhtml page but i want to get my application header and footer themes and those are defined in jsp now I tried looking for integrating jsp into xhtml but it was rightly suggested that one must not do it.

尝试过如何在Facelets页面中包含JSP页面?,但是它不能作为my标签无法识别,因此最终尝试创建jsp页面并在其中包含xhtml页面,该页面似乎可以正常运行,但并非100%.

Tried How to include a JSP page in a Facelets page? but that didn't work either as my tags were not recognized and so finally tried creating jsp page and included xhtml page inside it and that seemed to work but not 100%.

因此,如果我现在直接点击xhtml页面,则它可以正常工作,但是如果我点击jsp页面并显示header/footer信息,则icefaces或说jsf内容不能100%工作,希望能够阐明要实现的目标.

So as it stands right now if i hit xhtml page directly then it works but if i hit jsp page with header/footer information then icefaces or say jsf stuffs doesn't work 100%, hope am able to clarify what am trying to achieve.

更新2

js文件,但在jsp页面中不会引用.

js file from javax.faces.resources are referenced fine on xhtml page but are not referenced on jsp page.

推荐答案

必须由网络浏览器下载那些JS/CSS文件.不是服务器必须加载/包括那些JS/CSS文件.

It's the webbrowser who has got to download those JS/CSS files. It's not the server who has got to load/include those JS/CSS files.

因此,您在srchref属性中指定的路径将相对于当前请求URL进行解析,如在浏览器的地址栏中看到的那样.相对于JSP文件在公共Web内容中的位置,它们没有得到解决.

So, the path which you specified in src and href attributes are resolved relative to the current request URL as you see in browser's address bar. They are not resolved relative to the location of the JSP file in the public webcontent.

因此,如果您恰巧在请求URL中具有上下文路径

So, if you happen to have a context path in the request URL like so

http://localhost:8080/somecontextpath/page.jsp

然后例如,您的<link href="/css/Main.css">将由网络浏览器从以下URL下载

then for example your <link href="/css/Main.css"> would be downloaded by the webbrowser from the following URL

http://localhost:8080/css/Main.css

实际上应该是

http://localhost:8080/somecontextpath/css/Main.css

相应地修复它.

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

或者如果您使用的是Facelets

Or if you're using Facelets

<link rel="stylesheet" href="#{request.contextPath}/css/Main.css" type="text/css">

或者如果您使用的是JSF 2 <h:outputStylesheet>(和<h:outputScript>组件)

Or if you're using JSF 2 <h:outputStylesheet> (and <h:outputScript> components)

<h:outputStylesheet name="css/Main.css" />

(并将/css/js文件夹放在公共Webcontent的/resources子文件夹中)

(and put the /css and /js folders in /resources subfolder of public webcontent)

顺便说一句,以下几行绝对没有意义:

By the way, the following line makes absolutely no sense:

<jsp:include page="/trade_entry/UploadBlotter.xhtml"/>

您在这里混合使用视图技术.您不能将其中一个包括在内. Facelets是JSP的继承者.使用一个或另一个.您可以在1个Webapp中混合使用它们,但不能在1个视图中混合使用.

You're mixing view technologies here. You can't include the one in the other. Facelets is the successor of JSP. Use the one or the other. You can mix them in 1 webapp, but not in 1 view.

这篇关于应用程序中未引用的JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆