Вопрос

I've viewed other questions on here relating to the topic, and am still having trouble using the twitter bootstrap with my Spring Web application. From my understanding these two should not be too complex to use together, that you should be able to place the css, js folders in your project and link them pretty simply.

I've viewed the following, which both seem to use it differently:

This is what my file hierarchy looks like: enter image description here

in my index.jsp file I am trying to link it:

<html>
    <head>
        <meta charset="utf-8">
        <title>Fantastic Log-In page</title>
        <link rel="stylesheet" href="<c:url value="/resources/css/bootstrap.css" />"/>

But obviously I am doing something wrong because I get the following warning:

WARN  PageNotFound - No mapping found for HTTP request with URI [/SpringJDBC/resources/css/bootstrap.css] in DispatcherServlet with name 'dispatcherServlet'

I am very new to spring development so a lot of this doesn't fully come across. I would appreciate any tips on how to get bootstrap working with my spring web application.

Thank you.

Это было полезно?

Решение

I would guess that your spring MVC config is set to handle something like /*. So a request comes in for your stylesheet and it'll complain because it hasn't got a controller that matches this URL pattern. What you need is a way to tell spring which URL's are for static resources.

Try adding something like this to your MVC config.

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

For the above config to work you'd have to move all your static files into a folder called resources. You could name it something else.

Have a read of the docs for more info:

http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/mvc.html

You want 16.14.5

... oh yes and move them into src/main/webapp!

Другие советы

For the meantime I just used the following code off of the getbootstrapped website instead of my own copy of the bootstrap.

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top