我正在使用Tomcat中的一个项目,我遇到了一个JavaScript文件问题。我正在尝试使用pickadate.js,当我将所有内容都放在HTML文件中时,一切正常,但是当我编写一个读取html文件并将其打印到响应编写器的servlet时,日期选择器不起作用,我得到了在Web控制台中出现以下JavaScript错误:
10:37:53.100 SyntaxError: missing : in conditional expression picker.js:349
10:37:53.102 SyntaxError: missing ; before statement picker.date.js:293
10:37:53.106 TypeError: $(...).pickadate is not a function AdminBlackout:24
以下是我在servlet中阅读的HTML文件:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="pickadate.js-3.4.0/tests/dev/style.css">
<link rel="stylesheet" href="pickadate.js-3.4.0/lib/themes/default.css">
<link rel="stylesheet" href="pickadate.js-3.4.0/lib/themes/default.date.css">
<script src="pickadate.js-3.4.0/lib/picker.js"></script>
<script src="pickadate.js-3.4.0/lib/picker.date.js"></script>
<script src="pickadate.js-3.4.0/lib/legacy.js"></script>
</head>
<body>
<input class="datepicker" type="text">
<script type="text/javascript">
$('.datepicker').pickadate();
</script>
</body>
</html>
servlet生成的源与上面完全相同。当我直接在浏览器中加载html文件时,一切正常,没有JavaScript错误。 pickadate.js-3.4.0文件夹位于我的webapp的根目录中。如果有人对如何解决这个问题有任何想法,我将不胜感激。
更新
的web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>Admin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorAddTimeslots</servlet-name>
<servlet-class>AdvisorAddTimeslots</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorAddTimeslots</servlet-name>
<url-pattern>/AdvisorAddTimeslots</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorTimeslots</servlet-name>
<servlet-class>AdvisorTimeslots</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorTimeslots</servlet-name>
<url-pattern>/AdvisorTimeslots</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorCalendar</servlet-name>
<servlet-class>AdvisorCalendar</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorCalendar</servlet-name>
<url-pattern>/AdvisorCalendar</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorTimeslotDetails</servlet-name>
<servlet-class>AdvisorTimeslotDetails</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorTimeslotDetails</servlet-name>
<url-pattern>/AdvisorTimeslotDetails</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Homepage</servlet-name>
<servlet-class>Homepage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Homepage</servlet-name>
<url-pattern>/Homepage</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>StudentSearch</servlet-name>
<servlet-class>StudentSearch</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StudentSearch</servlet-name>
<url-pattern>/StudentSearch</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SaveTimeslots</servlet-name>
<servlet-class>SaveTimeslots</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SaveTimeslots</servlet-name>
<url-pattern>/SaveTimeslots</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>Admin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/Admin</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdminBlackout</servlet-name>
<servlet-class>AdminBlackout</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminBlackout</servlet-name>
<url-pattern>/AdminBlackout</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ConfirmTimeslot</servlet-name>
<servlet-class>ConfirmTimeslot</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ConfirmTimeslot</servlet-name>
<url-pattern>/ConfirmTimeslot</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SaveBlackout</servlet-name>
<servlet-class>SaveBlackout</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SaveBlackout</servlet-name>
<url-pattern>/SaveBlackout</url-pattern>
</servlet-mapping>
</web-app>
文件结构:
-tomcat
-webapps
-SANDBOX
-pickadate.js-3.4.0
-test.html
-web-inf
答案 0 :(得分:1)
这听起来像编码问题:
当Java读取文件时,请考虑它假定文件的编码是系统的默认编码。在Windows中,这意味着您使用的是ISO-8859-1的变体,而不是UTF-8,浏览器的默认编码是什么。 servlet如何读取文件?请求使用的编码是什么?