我正在尝试为我的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 © 2017, Zensar Ltd. All Rights Reserved </p>
</footer>
</div>
</body>
</html>
我已经像我这样构建了我的文件夹
答案 0 :(得分:1)
尝试使用
<link rel="stylesheet" href="/resources/LoginStyle.css" type="text/css" media="all">
或
<link rel="stylesheet" href="resources/LoginStyle.css" type="text/css" media="all">