gpt4 book ai didi

java - 文件和图像未加载 Spring MVC

转载 作者:行者123 更新时间:2023-12-02 12:27:54 25 4
gpt4 key购买 nike

我正在尝试为我的 Spring MVC 项目加载 CSS 和图像,但 CSS 和图像没有启动。我尝试了很多方法,甚至将我的 jar 更新到 4.0.0。

这是我的 servlet

<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd" >

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


<context:component-scan base-package = "com.pack.model, com.pack.controllers" />

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

<bean id="dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name = "driverClassName" value = "com.mysql.jdbc.Driver"/>
<property name = "url" value = "jdbc:mysql://localhost:3306/test"/>
<property name = "username" value = "bafana"/>
<property name = "password" value = "bafana"/>
</bean>

<!-- Definition for login dao bean -->
<bean id = "loginDao" class = "com.database.accessobjects.LoginDao">
<property name = "dataSource" ref = "dataSource" />
</bean>

</beans>

这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<display-name>Spring MVC Form Handling</display-name>

<servlet>
<servlet-name>HelpDesk</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelpDesk</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

这是我的 loginModel.jsp 登录文件,CSS 和图像应在其中加载

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"  pageEncoding="ISO-8859-1"%>
<%@taglib uri = "http://www.springframework.org/tags/form" prefix = "form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<spring:url value="/resources/LoginStyle.css" var="KstyleCSS-login" />
<spring:url value="/resources/zensar.png" var="zensar-logo-login" />

<link rel="stylesheet" href="${KstyleCSS-login}" type="text/css" media="all">

</head>
<body>
<div class="main-div">
<div class="logo"><img src="${zensar-logo-login}" alt="zensar.png"></img></div>
<div class="header">
<h2>Help-Desk Services</h2>
<h5><strong>${msg}</strong></h5>
</div>
<div class="logIn container">
<form:form method = "POST" action = "/HelpDesk/logMeIn" class="form-horizontal">
<div class="form-group row">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user" aria-hidden="true"></i></span>
<form:input path = "username" type="text" class="form-control" name="username" id="username" placeholder="Enter your username"/>
</div>
</div>
</div>
<div class="form-group row">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock" aria-hidden="true"></i></span>
<form:input path = "password" class="form-control" name="password" id="password" placeholder="Enter your Password"/>
</div>
</div>
</div>
<div class="form-group row">
<div class="cols-sm-10">
<input name="mysubmit" id="submit" type="submit" class="btn" value="Login"/>
</div>
</div>
</form:form>
</div>
<footer>
<p>Copyright &copy; 2017, Zensar Ltd. All Rights Reserved </p>
</footer>
</div>
</body>
</html>

我的文件夹结构如下

最佳答案

尝试只使用

<link rel="stylesheet" href="/resources/LoginStyle.css" type="text/css" media="all">

<link rel="stylesheet" href="resources/LoginStyle.css" type="text/css" media="all">

关于java - 文件和图像未加载 Spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45416201/

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