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

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

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

问题

以下是翻译好的部分:

jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- 静态内容 -->
<link rel="stylesheet" href="/resources/css/style.css">
<script type="text/javascript" src="/resources/js/app.js"></script>
<title>Spring Boot</title>
</head>
<body>
  <h1>Spring Boot - MVC web application example</h1>
  <hr>

  <div class="form">
    <form action="hello" method="post" onsubmit="return validate()">
      <table>
        <tr>
          <td>Enter Your name</td>
          <td><input id="name" name="name"></td>
          <td><input type="submit" value="Submit"></td>
        </tr>
      </table>
    </form>
  </div>

</body>
</html>

app.properties

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

tree

java
-*.java

resources
-css
--*.css
-js
--*.js

webapp
-WEB-INF
--view
---*.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

&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot; pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;

&lt;!-- Static content --&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;/resources/css/style.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/resources/js/app.js&quot;&gt;&lt;/script&gt;

&lt;title&gt;Spring Boot&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h1&gt;Spring Boot - MVC web application example&lt;/h1&gt;
  &lt;hr&gt;

  &lt;div class=&quot;form&quot;&gt;
    &lt;form action=&quot;hello&quot; method=&quot;post&quot; onsubmit=&quot;return validate()&quot;&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td&gt;Enter Your name&lt;/td&gt;
          &lt;td&gt;&lt;input id=&quot;name&quot; name=&quot;name&quot;&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/form&gt;
  &lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;

app.properties

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

tree

java
-*.java

resources
-css
--*.css
-js
--*.js

webapp
-WEB-INF
--view
---*.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:

确定