简体   繁体   中英

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 . The web application is being created in Java and the table is created but not with the CSS style. I am 100% new to html and javascript and just started trying to learn things today.

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. How should I reference a Javascript library from a JSP in Java Web Application?

I have made some progress but I still cannot get it to work properly. This is my WelcomePage.jsp file:

<%@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. I have also attempted to add it to the web.xml file but nothing seems to work.

文件层次

Some things I have already tried

Can not include javascript file from WEB-INF directory in JSP.

how to reference a java .class file from a JSP page?

Put it at the root of your application, or under a /scripts folder there. WEB-INF and META-INF are not accessible from outside.

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.

Then, if everything is ok, I suppose you need to invoke some function and pass the table id.

由于您将要创建网页,并且可能需要更多的js库,因此为什么不在Web页中创建一个仅用于js的新文件夹呢?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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