我正在用Java编写一个小型web应用程序。我想为图书馆的图书建立一个评分系统,当最终用户查看书的细节和对这本书的评价时。我使用http://tech.pro/tutorial/931/how-to-build-a-star-ratings-jquery-plugin来实现它。我的jsp页面是:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Star rating demo</title>
<link type="text/css" rel="stylesheet" href="../css/jquery.ratings.css" />
<script src="../js/jquery-1.3.2.min.js"></script>
<script src="../js/jquery.ratings.js"></script>
<script src="../js/example.js"></script>
<s:head/>
</head>
<body>
<div id="example-1"></div> <br />
Your Rating: <span id="example-rating-1">not set</span>
<br /><br />
<div id="example-2"></div> <br />
Your Rating: <span id="example-rating-2">not set</span>
<h1><s:text name="welcome" /></h1>
</body>
但是星号不在浏览器中显示,我使用Netbeans并在WEB中创建名称为“css”和“js”的文件夹。
css -> jquery.ratings.css和明星图片
在js文件夹中:
js -> jquery.ratings.js和jQuery1.3.2.min.js和example.js
但是当我运行这个应用程序时,星号就不会显示了。有谁可以帮我?
原谅我的英语。
发布于 2013-04-20 15:47:33
浏览器必须下载CSS文件和JS文件。webapp正是prower无法下载的目录:它包含配置、类和jar fiels,它们必须保持对WEB应用程序的私有。所以你不应该把这些文件放到WEB中。
如果浏览器地址栏中显示的URL为http://localhost/myApp/foo/bar.jsp,而您在JSP中的相对URL为../js/example.js,则浏览器将在URL中下载JS文件。因此,在这种情况下,JS文件应该位于一个名为js的目录中,位于webapp根目录下。
如果URL为http://localhost/myApp/foo/bar/baz/bang/bing.jsp,则浏览器将在URL http://localhost/myApp/foo/bar/baz/js/example.js中查找JS文件。我的建议是:不要为您的JS和CSS文件使用相对路径(事实上,对于其他所有文件)。使用绝对路径:
<script src="<c:url value='/js/example.js'/>"></script>这样,不管页面的URL是什么,浏览器总是会在URL http://localhost/myApp/js/example.js上查找JS文件。
https://stackoverflow.com/questions/16121183
复制相似问题