[英]How can I reference a javascript library from a JSP in a java web application?
I am trying to create a table with sortable columns using a javascript library provided by this website . 我正在尝试使用此网站提供的javascript库创建具有可排序列的表格。 The web application is being created in Java and the table is created but not with the CSS style.
正在用Java创建Web应用程序,并创建表,但不使用CSS样式。 I am 100% new to html and javascript and just started trying to learn things today.
我是html和javascript的100%新手,今天才开始尝试学习。
I have placed the library in the same source folder as the JSP and also at the root of the project but both times the table is created in standard html format without the script formatting. 我将库与JSP放在相同的源文件夹中,也放在项目的根目录下,但是两次都以标准html格式创建表,而没有脚本格式。 How should I reference a Javascript library from a JSP in Java Web Application?
如何在Java Web应用程序中从JSP引用Javascript库?
I have made some progress but I still cannot get it to work properly. 我已经取得了一些进展,但是仍然无法正常工作。 This is my WelcomePage.jsp file:
这是我的WelcomePage.jsp文件:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%response.setHeader("Refresh", "5");%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
<script type="text/javascript" src="sorttable.js"></script>
</head>
<body>
<p><a href=url target=\"_blank\">Start</a></p>
<table class="sorttable">
<tr>
<td>text </td>
<td>text </td>
<td>text </td>
<td>text </td>
<td>text </td>
</tr>
</table>
</body>
</html>
I have tried placing it into the META-INF, WEB-INF, and the root folders none of them seem to work correctly. 我尝试将其放入META-INF,WEB-INF和根文件夹中,但它们似乎都无法正常工作。 I have also attempted to add it to the web.xml file but nothing seems to work.
我也尝试将其添加到web.xml文件中,但似乎没有任何效果。
Some things I have already tried 我已经尝试过的一些东西
Can not include javascript file from WEB-INF directory in JSP. 无法在JSP中包含来自WEB-INF目录的javascript文件。
how to reference a java .class file from a JSP page? 如何从JSP页面引用Java .class文件?
Put it at the root of your application, or under a /scripts folder there. 将其放在应用程序的根目录下,或/ scripts文件夹下。 WEB-INF and META-INF are not accessible from outside.
不能从外部访问WEB-INF和META-INF。
If it is not accessible, then check the logs, try opening the js file manually in the browser, and check with Firebug (or similar tool) if there aren't javascript errors. 如果无法访问,请检查日志,尝试在浏览器中手动打开js文件,然后使用Firebug(或类似工具)检查是否没有javascript错误。
Then, if everything is ok, I suppose you need to invoke some function and pass the table id. 然后,如果一切正常,我想您需要调用一些函数并传递表ID。
由于您将要创建网页,并且可能需要更多的js库,因此为什么不在Web页中创建一个仅用于js的新文件夹呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.