gpt4 book ai didi

javascript - Spring - [CSS, JS, Images] 我超棒的风格在哪里?

转载 作者:太空宇宙 更新时间:2023-11-04 07:04:07 25 4
gpt4 key购买 nike

我是 Spring 新手。

我开始了一个家庭元素,我决定使用 Spring MVC 来处理我的 Servlet 等。我下载了一个 Bootstrap 主题(不用担心样式)。我有一个运行良好的 Servlet,但我想提高我的 Spring 技能,所以我开始将 Servlet 重建为 Spring MVC servlet。完成后,我意识到我所有的 css、js 内容和显然我的图像都没有加载到页面上。我尽可能快地寻找解决它的机会……但我坚持了下来。加载了一些 css 和 js 但是..我两天前还没有看到我很棒的基于 Bootstrap 的主题。我现在有点绝望了。这里有一些代码,向你们展示我是如何尝试解决这个问题的:网页.xml

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

spring-mvc-servlet.xml

<mvc:resources mapping="/resources/**" location="/resources/public/"/>

<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property value="/" name="prefix" />
<property value=".jsp" name="suffix" />
</bean>

我的元素结构:

WebContent
META-INF
resources[folder]
public[folder]
contactform[folder]
js files
css[folder]
css files
img[folder]
images, and folders with more images
js[folder]
one js file
libraries[folder]
folders with js files (and it contains css files as well(in css-named folders))
WEB-INF
lib
spring-mvc-servlet.xml
web.xml

头部部分

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
<title>...</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="" name="keywords">
<meta content="" name="description">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700|Raleway:300,400,400i,500,500i,700,800,900" rel="stylesheet">
<link href="/resources/libraries/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/resources/libraries/nivo-slider/css/nivo-slider.css" type="text/css" rel="stylesheet">
<link href="/resources/libraries/owlcarousel/owl.carousel.css" type="text/css" rel="stylesheet">
<link href="/resources/libraries/owlcarousel/owl.transitions.css" type="text/css" rel="stylesheet">
<link href="/resources/libraries/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet">
<link href="/resources/libraries/animate/animate.min.css" type="text/css" rel="stylesheet">
<link href="/resources/libraries/venobox/venobox.css" type="text/css" rel="stylesheet">
<link href="/resources/css/nivo-slider-theme.css" type="text/css" rel="stylesheet">
<link href="/resources/css/style.css" type="text/css" rel="stylesheet">
<link href="/resources/css/responsive.css" type="text/css" rel="stylesheet">

我的 js 文件在正文底部调用:)

感谢您的回答,如果您需要更多信息,请告诉我..我会更新我的问题!

最佳答案

终于解决了!

我一直在搜索......直到找到解决方案。所以这是我完成的步骤:

  1. 我已将我所有的 css/js/image 内容移动到 WebContent/resources/...下
  2. 我已经更改了 mvc servlet xml
  3. 最后..我已经更改了所有链接和来源

所以这是 xml:

<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property value="/" name="prefix" />
<property value=".jsp" name="suffix" />
</bean>

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />

和引用文献

<script src="${pageContext.servletContext.contextPath}/resources/libraries/jquery/jquery.min.js"></script>

所以,我希望这篇文章能帮助像我一样绝望的人。

关于javascript - Spring - [CSS, JS, Images] 我超棒的风格在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51766459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com