java - Spring MVC CSS Error Loading -


i using spring , while running page without css running perfectly. when include css file looks plain without css. while clicking on link in view source shows error 404 . me on

web.xml

<web-app id="webapp_id" version="2.4"    xmlns="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xsi:schemalocation="http://java.sun.com/xml/ns/j2ee     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">     <display-name>spring mvc application</display-name>     <servlet>       <servlet-name>helloweb</servlet-name>       <servlet-class>          org.springframework.web.servlet.dispatcherservlet       </servlet-class>       <load-on-startup>1</load-on-startup>    </servlet>     <servlet-mapping>       <servlet-name>helloweb</servlet-name>       <url-pattern>/</url-pattern>    </servlet-mapping>  </web-app> 

servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"   xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xsi:schemalocation="    http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc.xsd    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd    ">      <context:component-scan base-package="com.ksv" />     <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">       <property name="prefix" value="/web-inf/jsp/" />       <property name="suffix" value=".jsp" />    </bean>     <mvc:resources mapping="/resources/**" location="/resources/css/"       cache-period="31556926"/>     <mvc:annotation-driven />  </beans> 

controller:

package com.ksv; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.ui.modelmap;  @controller @requestmapping("/") public class hellocontroller{     @requestmapping(method = requestmethod.get)    public string printhello(modelmap model) {         return "hello";    }  } 

jsp:

<!doctype html> <html >   <head>     <meta charset="utf-8">     <title>ksv</title>        <link href="${pagecontext.request.contextpath}/resources/css/style.css" rel="stylesheet" >     </head>   <body>      <div class="wrapper">     <div class="container">         <h1>login</h1>                  <form class="form" action="login" method="post">             <input type="text" name = "username" placeholder="username">             <input type="password" name ="userpass" placeholder="password">             <button type="submit" id="login-button">login</button>         </form>     </div>      <ul class="bg-bubbles">         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>         <li></li>     </ul> </div>     <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>         </body> </html> 

file structure:

helloweb     -webcontent         -meta-inf         -resources         -web-inf             -jsp             -hello.jsp         -servlet.xml         -web.xml 

just remove css/ location attribute of mvc resource cnfiguration.

change :

<mvc:resources mapping="/resources/**" location="/resources/css/"       cache-period="31556926"/> 

to

<mvc:resources mapping="/resources/**" location="/resources/"       cache-period="31556926"/> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -