使用Tomcat引用Javascript库 [英] Referencing Javascript libraries with Tomcat

查看:168
本文介绍了使用Tomcat引用Javascript库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Eclipse Ganymede Tomcat 5.5 。我想添加一些javascript,特别是ajax功能到一个动态的Web项目,需要一些帮助。

I am using Eclipse Ganymede and Tomcat 5.5. I would like to add some javascript and especially ajax functionality to a dynamic web project and need some help.

我想使用jquery(但我可以接受其他建议如果你告诉我为什么另一个图书馆在这种情况下会更好,但是我选择了jquery,因为它应该是简单的(在第一个看起来似乎是这样))。

I would like to use jquery (but I am open to other suggestions, if you tell me why another library would be better in this case, but I have chosen jquery because it is supposed to be simple (which on the first look it seems to be)).

我有两个问题:

1 - Tomcat找不到jquery库。我在我的jsp文件中尝试了几件事情,如:

1- Tomcat can't find the jquery library. I tried several things in my jsp file like:

   <script type="text/javascript" src="WEB-INF/lib/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" src="/WEB-INF/lib/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" src="./WEB-INF/lib/jquery-1.3.2.min.js"></script>

正如你所看到的,我将jquery库投入到 / WEB-INF / lib中。在没有tomcat(最后一个路径版本)的浏览器中执行jsp文件的工作,所以路径是正确的。

As you can see, I threw the jquery library in /WEB-INF/lib. Executing the jsp file within a browser without tomcat (with the last path version) works, so the path is correct.

2-在动态Web项目中没有适当的语法高亮显示jquery,没有弹出式建议。我还尝试了这篇文章中的信息,但并没有太大变化。

2- There is no proper syntax highlighting within the dynamic web project for jquery and no popup suggestions. I also tried the information in this article, but it didn't change much.

推荐答案

更具体(因为花了我半个小时的时间才能看出到达这一点后):

To be more specific (because it took me about half an hour to figure this out after getting to this point):

当您在Eclipse中使用Tomcat创建动态Web项目时,除了其他项目之外,还可以获得名为WebContent的文件夹。这是将部署到Tomcat服务器的实际文件夹,在Eclipse相当于 Tomcat / webapps /<项目名称> (我不知道它真正存在于何处)。出于安全考虑,作为特殊情况,没有人可以访问那里的 META-INF WEB-INF 文件夹将脚本放在这些地方不会有帮助。

When you create a Dynamic Web Project with Tomcat in Eclipse, among other things in the project you get a folder named "WebContent". That's the actual folder that gets deployed to the Tomcat server, in Eclipse's equivalent of Tomcat/webapps/<project name> (I'm not sure where it really exists). For security reasons, as a special case nobody can access the META-INF and WEB-INF folders in there, so putting your scripts in those places will not help.

您需要做的是在WebContent内创建一个文件夹,并将Javascript粘贴到其中。这个文件夹将是全局可见的,所以访问你的站点(像你,当你测试它)可以实际到达Javascript。

What you have to do is create a folder inside of WebContent, and stick your Javascript in there. This folder will be globally visible, so visitors to your site (like you, when you test it) can actually get to the Javascript.

我做了什么,在WebContent中创建了一个名为script的文件夹,并将我的Javascript放在那里;那么当我需要在页面中引用它时,我把 src =ProjectName / script / AwesomesauceJavascript.js

What I did, for instance, was create a folder named "script" in WebContent and put my Javascript in there; then, when I needed to reference it in a page, I put in src="ProjectName/script/AwesomesauceJavascript.js"

这篇关于使用Tomcat引用Javascript库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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