如何在.jsp文件中连接css和javascript

问题描述 投票:0回答:1

我在将外部 css 和 javascript 文件连接到其 jsp 时遇到问题。

我尝试按照在谷歌上阅读的方式进行WebConfig,但我意识到我的jsp文件路径是通过application.properties完成的,因此当它运行时它会覆盖application.properties并且无法找到.jsp。我删除了 WebConfig 并坚持使用 application.properties 并尝试为 css 添加文件路径

spring.mvc.view.prefix=/WEB-INF/views/ 
spring.mvc.view.suffix=.jsp  
spring.web.resources.statstaticic-locations=classpath:/static/,classpath:/public/,classpath:/resources/,classpath:/META-INF/resources/ 

这些使 JSP 运行,但无法读取 css。

JSP 的文件路径: src-> main -> webapp-> home.jsp home.jsp:

<head> 
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" href="c:url value='/css/home.css' />">     
<title>Project One</title> </head> <body>

CSS 文件路径: src-> main-> resources-> static-> css-> home.css

我不确定这是否重要,但这些是我正在使用的依赖项(gradle):

dependencies {

   implementation 'org.springframework.boot:spring-boot-starter-web'
   developmentOnly 'org.springframework.boot:spring-boot-devtools'
   testImplementation 'org.springframework.boot:spring-boot-starter-test'
  implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
  runtimeOnly 'com.mysql:mysql-connector-j'



   runtimeOnly 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.9' //jsp
   runtimeOnly 'org.glassfish.web:jakarta.servlet.jsp.jstl:3.0.0'  //helpful jsp tags
 
java spring-boot spring-mvc jsp spring-data-jpa
1个回答
0
投票

您尚未配置静态资源或尝试配置但属性名称错误。

默认情况下,Spring Boot 将从名为

/static
(或
/public
/resources or 
/META-INF/resources
) in the classpath or from the root of the
ServletContext` 的目录提供静态内容。

© www.soinside.com 2019 - 2024. All rights reserved.