简体   繁体   English

在我的JSP中找不到使用jQuery的方法,请帮帮我

[英]Can't find a way to use jQuery in my JSP, help me please

I'm actually working on a website using JSP and Servlet. 我实际上正在使用JSP和Servlet的网站上工作。

I'm not a pro so I try to do my best and I wanted to implement a calendar that would show up on one of my webpages. 我不是专业人士,所以我会尽力而为,我想实现一个日历,该日历将显示在我的一个网页上。

I checked the web and found this : http://arshaw.com/fullcalendar/ 我检查了一下网页,发现了这一点: http : //arshaw.com/fullcalendar/

It seemed promising so even though I'm a noob in JS I downloaded the package and tried to use it. 看起来很有希望,所以即使我不是JS的菜鸟,我还是下载了该软件包并尝试使用它。

But that didn't work. 但这没有用。

I've tried a lot of things and I'm going to die if I can't find a solution to this. 我已经尝试了很多事情,如果找不到解决方案,我将会死掉。

The problem comes from jQuery, which doesn't work. 问题来自jQuery,它不起作用。 At all. 完全没有

Here's my code : 这是我的代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Planning</title>
        <link rel="stylesheet" type="text/css" href="./styleERDF.css" media="screen">
        <link rel="stylesheet" type="text/css" href="./styleImpression.css" media="print">
        <link rel="stylesheet" type="text/css" href="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\fullcalendar\fullcalendar.css" media="all">
        <link rel="stylesheet" type="text/css" href="./styleMenu.css" media="screen">
        <script type="text/javascript" src="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\lib\jquery.min.js"></script>
        <script type="text/javascript" src="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\fullcalendar\fullcalendar.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                alert("PLEASE WORK");                
            });
        </script>
    </head>
    <body>
        <div id="general">

            <div id="entete" >
                <h1><img src="Images\ERDF.png" width="Auto" height="Auto" alt="ERDF"></h1>
            </div>
            <div class="noImpr" id="menu">
                <%@ include file="../menu.html"%>                
            </div>
        </div>
    </body>
</html>

The fact is : nothing works. 事实是:没有任何效果。 I mean, HTML does. 我的意思是,HTML确实如此。 The webpage loads and show the first image and the menu.html, but the script doesn't do anything. 该网页会加载并显示第一张图片和menu.html,但是脚本不会执行任何操作。 Isn't it supposed to show me a message ? 它不是应该给我显示消息吗?

You can see that I used the full path for the jQuery file, because I really was desperated. 您会看到我使用了jQuery文件的完整路径,因为我真的很沮丧。 I'm working on two computers, this one who has Internet access, and an other one, on which I program, who doesn't have Internet access, so I can't use web url. 我正在使用两台计算机,其中一台可以访问Internet,另一台可以在我编程的计算机上访问互联网,因此无法使用Web URL。

EDIT: 编辑:

Current project structure (current jsp in folder "pages": 当前项目结构(文件夹“页面”中的当前jsp:

http://i.stack.imgur.com/9bVBb.png http://i.stack.imgur.com/9bVBb.png

The problem is that you're loading the files from local disk. 问题是您正在从本地磁盘加载文件。 Load them directly from the web application resources. 直接从Web应用程序资源中加载它们。 Usually, you do this using ${request.contextPath} that already contains http://yourIp/yourApplicationName : 通常,您使用已经包含http://yourIp/yourApplicationName ${request.contextPath}进行此操作:

<script type="text/javascript" src="${request.contextPath}/calendar/lib/jquery.min.js"></script>

Rewriting all your sources to this style: 将所有源重写为这种样式:

<link rel="stylesheet" type="text/css" href="${request.contextPath}/styleERDF.css" media="screen">
<link rel="stylesheet" type="text/css" href="${request.contextPath}/styleImpression.css" media="print">
<link rel="stylesheet" type="text/css" href="${request.contextPath}/calendar/fullcalendar/fullcalendar.css" media="all">
<link rel="stylesheet" type="text/css" href="${request.contextPath}/styleMenu.css" media="screen">
<script type="text/javascript" src="${request.contextPath}/calendar/lib/jquery.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/calendar/fullcalendar/fullcalendar.min.js"></script>

<!-- ... -->

<img src="${request.contextPath}/Images/ERDF.png" width="Auto" height="Auto" alt="ERDF">

Note that example above will work only on JSP pages. 请注意,上面的示例在JSP页面上有效。 If working in HTML page, then you have to call the resources statically from the current path: 如果在HTML页面中工作,则必须从当前路径静态调用资源:

<link rel="stylesheet" type="text/css" href="./styleERDF.css" media="screen">
<script type="text/javascript" src="./calendar/lib/jquery.min.js"></script>

Before you cram HTML into a JSP, get it working as a plain HTML file. 在将HTML塞入JSP之前,请先将其作为纯HTML文件使用。 I think the single backslashes are incorrect, try using single forward slashes. 认为单个反斜杠是不正确的,请尝试使用单个正斜杠。 Also, as someone else pointed out, you will have better luck using a relative path. 另外,正如其他人指出的那样,使用相对路径会带来更好的运气。 You can serve HTML from your Java Web App server, just put it in the "WebContent" folder or whatever you named it in your project. 您可以从Java Web App服务器提供HTML,只需将其放在“ WebContent”文件夹中或在项目中命名的任何内容即可。

使用CDN

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

Change from this: 从此更改:

<script type="text/javascript" src="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\lib\jquery.min.js"></script>
<script type="text/javascript" src="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\fullcalendar\fullcalendar.min.js"></script>

To This 对此

<script type="text/javascript" src="../calendar/lib/jquery.min.js"></script>
<script type="text/javascript" src="../calendar/fullcalendar/fullcalendar.min.js"></script>

I am assuming that the "SiteWebERDF" directory on your machine is the one that has JSP in it. 我假设您计算机上的“ SiteWebERDF”目录是其中包含JSP的目录。 More info can be found here on relative paths: http://www.w3.org/TR/WD-html40-970917/htmlweb.html#h-5.1.2 在相对路径上可以找到更多信息: http : //www.w3.org/TR/WD-html40-970917/htmlweb.html#h-5.1.2

+1 for Jason P. But if you MUST load full file paths... Jason P +1。但是,如果您必须加载完整的文件路径...

Instead of: 代替:

<script type="text/javascript" src="C:\Users\Maxime\Documents\NetBeansProjects\SiteWebERDF\web\calendar\lib\jquery.min.js
</script>

Use this (presuming you are on Windows: 使用此(假设您在Windows上:

<script type="text/javascript" src="file:///C:/Users/Maxime/Documents/NetBeansProjects/SiteWebERDF/web/calendar/lib/jquery.min.js">
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM