Вопрос:

CSS files still not being loaded in the JSP files of a Spring MVC web app

java css spring jsp spring-mvc

75 просмотра

3 ответа

0 Репутация автора

Can anyone help me find a solution to this puzzle, I've been trying for three days and still the server responds with a 505. I even have a similar project that works in this regard, and I've copied all of the critical code but the one in question still won't budge.

I've posted pictures that will perhaps enable someone to spot an error that I somehow haven't been aware of. Thanks in advance!

1.) This is my refresh response:

2.) This is the landing response:

3.) This is my project:

4.) This is my dispacher-servlet.xml config file:

5.) This is my header.jsp file with the spring:url necessary for css inclusion:

And here is the embeded code snippets:

dispacher-servlet.xml:

    <?xml version="1.0" encoding="UTF-8"?>

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

    <context:component-scan base-package="controllers" />

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

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

        <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
            <list>
                <value>/WEB-INF/data/dragon</value>
            </list>
            </property>
            <property name="defaultEncoding" value="UTF-8" />
        </bean>

        <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
            <property name="defaultLocale" value="en" />
        </bean>

        <mvc:interceptors>
            <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="language"/>
            </bean>
        </mvc:interceptors>

    <aop:aspectj-autoproxy/>
    <bean id="dragonDao" class="controllers.DragonDaoImp"/>
    <bean id="logAspect" class="controllers.LoggingAspect"/>

<!--        <import resource="flow-definition.xml"/> -->
</beans>

header.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" http-equiv="Content-Type" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <meta name="description" content="">
      <meta name="author" content="">
      <title>Testing 3-5-5</title>
      <!--<link href="webjars/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> -->
      <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
      <spring:url value="/resources/version1/css/footer.css" var="footerCSS"/>
      <link href="${footerCSS}" rel="stylesheet"/>
      <spring:url value="/resources/version1/css/header.css" var="headerCSS"/>
      <link href="${headerCSS}" rel="stylesheet"/>
   </head>
   <body style="background-color: #C5D1EB;"> 
      <nav class="navbar navbar-inverse" id="navbar" style="border-radius: 0px; padding-top:1px; border-color: #222222;">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">ServiceName</a> 
            <!-- style="margin-right: 200px;" -->
            </div>
            <div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
                        <li class="active">
                            <a href="#" style="border-radius: 0px;" class="btn btn-outline-success">
                                <span class="glyphicon glyphicon-home"></span> Home
                            </a>
                        </li>
                        <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">DZs <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="dragon">DZ03</a>
                                </li>
                                <li><a href="#">DZ04</a>
                                </li>
                                <li><a href="#">DZ05</a>
                                </li>
                                <li><a href="#">DZ06</a>
                                </li>
                                <li><a href="#">DZ07</a>
                                </li>
                            </ul>
                        </li>
                        <li><a href="#">Menu 1</a>
                        </li>
                        <li><a href="#">Menu 2</a>
                        </li>
                    </ul>
                  <form class="navbar-form navbar-right">
                    <div class="form-group">
                      <input type="text" placeholder="Email" class="form-control">
                    </div>
                    <div class="form-group">
                      <input type="password" placeholder="Password" class="form-control">
                    </div>
                    <button type="submit" style="background-color: #32936F; border-color: #32936F;" class="btn btn-success">Sign in</button>
                  </form>
                </div>
            </div>
        </div>
    </nav>
Автор: user8910040 Источник Размещён: 08.11.2017 11:06

Ответы (3)


0 плюса

1 Репутация автора

Looks you have provided relative path for the CSS where it is expecting absolute path. Could you please try like below by adding contextPath. ${pageContext.request.contextPath}/resources/version1/css/footer.css

Автор: Maddy Размещён: 08.11.2017 11:22

0 плюса

1 Репутация автора

Please try <mvc:resources mapping="/resources/**" location="/resources/version1/" /> and <link href="<c:url value="/resources/css/header.css" />" rel="stylesheet">

Автор: K.Nikita Размещён: 08.11.2017 11:25

0 плюса

0 Репутация автора

Решение

The solution came up with just fiddling with the entire code rep. Can't really explain what cured the error. I apologize for a poor solution answer, this project (home assignment) is no longer maintained.

Автор: user8910040 Размещён: 18.06.2018 07:07
Вопросы из категории :
32x32