如何在Spring Boot的JSP文件中导入JS文件。

huangapple 未分类评论45阅读模式
英文:

how can i import js file on my jsp file in springboot

问题

以下是翻译好的部分:

jsp

  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6. <!-- 静态内容 -->
  7. <link rel="stylesheet" href="/resources/css/style.css">
  8. <script type="text/javascript" src="/resources/js/app.js"></script>
  9. <title>Spring Boot</title>
  10. </head>
  11. <body>
  12. <h1>Spring Boot - MVC web application example</h1>
  13. <hr>
  14. <div class="form">
  15. <form action="hello" method="post" onsubmit="return validate()">
  16. <table>
  17. <tr>
  18. <td>Enter Your name</td>
  19. <td><input id="name" name="name"></td>
  20. <td><input type="submit" value="Submit"></td>
  21. </tr>
  22. </table>
  23. </form>
  24. </div>
  25. </body>
  26. </html>

app.properties

  1. spring.mvc.view.prefix = /WEB-INF/views/
  2. spring.mvc.view.suffix = .jsp
  3. spring.mvc.static-path-pattern=/resources/**

tree

  1. java
  2. -*.java
  3. resources
  4. -css
  5. --*.css
  6. -js
  7. --*.js
  8. webapp
  9. -WEB-INF
  10. --view
  11. ---*.jsp

如何在Spring Boot的JSP文件中导入JS文件。

英文:

i just load css and js on my jsp

but it just load css not js

this is my code

jsp

  1. &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot; pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  2. &lt;!DOCTYPE html&gt;
  3. &lt;html&gt;
  4. &lt;head&gt;
  5. &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  6. &lt;!-- Static content --&gt;
  7. &lt;link rel=&quot;stylesheet&quot; href=&quot;/resources/css/style.css&quot;&gt;
  8. &lt;script type=&quot;text/javascript&quot; src=&quot;/resources/js/app.js&quot;&gt;&lt;/script&gt;
  9. &lt;title&gt;Spring Boot&lt;/title&gt;
  10. &lt;/head&gt;
  11. &lt;body&gt;
  12. &lt;h1&gt;Spring Boot - MVC web application example&lt;/h1&gt;
  13. &lt;hr&gt;
  14. &lt;div class=&quot;form&quot;&gt;
  15. &lt;form action=&quot;hello&quot; method=&quot;post&quot; onsubmit=&quot;return validate()&quot;&gt;
  16. &lt;table&gt;
  17. &lt;tr&gt;
  18. &lt;td&gt;Enter Your name&lt;/td&gt;
  19. &lt;td&gt;&lt;input id=&quot;name&quot; name=&quot;name&quot;&gt;&lt;/td&gt;
  20. &lt;td&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;&lt;/td&gt;
  21. &lt;/tr&gt;
  22. &lt;/table&gt;
  23. &lt;/form&gt;
  24. &lt;/div&gt;
  25. &lt;/body&gt;
  26. &lt;/html&gt;

app.properties

  1. spring.mvc.view.prefix = /WEB-INF/views/
  2. spring.mvc.view.suffix = .jsp
  3. spring.mvc.static-path-pattern=/resources/**

tree

  1. java
  2. -*.java
  3. resources
  4. -css
  5. --*.css
  6. -js
  7. --*.js
  8. webapp
  9. -WEB-INF
  10. --view
  11. ---*.jsp

如何在Spring Boot的JSP文件中导入JS文件。

huangapple
  • 本文由 发表于 2020年7月24日 19:02:58
  • 转载请务必保留本文链接:https://java.coder-hub.com/63072273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定