Spring MVC Js和css不加载

时间:2016-09-06 10:17:07

标签: javascript css jsp spring-mvc

我知道这是一个重复的问题,但我无法通过查看另一个问题的解决方案来解决问题。但是我已经完成了上一个问题中提出的所有建议 这就是为什么我用我的代码询问问题,请看我的代码有什么问题 我的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/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>HMSLoginMVCSpring</display-name>
  <servlet>
     <servlet-name>spring-dispatcher</servlet-name>
     <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
     </servlet-class>
 </servlet>
 <servlet-mapping>
     <servlet-name>spring-dispatcher</servlet-name>
     <url-pattern>/</url-pattern>
 </servlet-mapping>
</web-app>  

我的调度员

    <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


   <context:component-scan base-package="com.java.Package.Login"></context:component-scan>

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

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">

            <value>/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>


</beans>  

我的控制器类

 package com.java.Package.Login;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {
    @RequestMapping(value="/Login.html", method=RequestMethod.GET)
    public ModelAndView getLoginForm(){
        ModelAndView model = new ModelAndView("Login");
        return model;

    }
    @RequestMapping(value="/submitForm.html", method=RequestMethod.POST)
    public ModelAndView getData(@RequestParam Map<String,String> loginData){
        String loginId= loginData.get("LoginId");
        String password= loginData.get("Password");
        ModelAndView model = new ModelAndView("Login");
        if(loginId.equals("vipul")&& password.equals("singh")){
            model.addObject("SucessMsg", "Your are authorised user and your user Id is "+loginId+" and password is "+password);         
        }
        else{
            model.addObject("SucessMsg","Wrong Login Id and Password");
        }

        return model;

    }
}

我的登录页

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!DOCTYPE Html>
<html lang="en">
<title>Aventyn&reg;| Login</title>
    <head>
        <link type="text/css" rel="stylesheet" href='<spring:url value="/resources/css/bootstrap.min.css" />' >
        <link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/css/loginCSS.css" />'>



    </head>
    <body>
        <div class="container-fluid">
            <form action="http://localhost:8087/HMSLoginMVCSpring/submitForm.html" method="post">
            <div class="row margin_Div">
                <div class="col-sm-12">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h2 class="panel-title text-center"><strong>Login Page</strong></h2>
                        </div>
                        <div class="panel-body">  
                            <div class="row">
                                <div class="col-sm-3 col-md-2">
                                    <b>Login Id:</b>
                                </div>
                                <div class="col-sm-4 col-md-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">*</span>
                                        <input type="text" class="form-control input-sm" placeholder="LoginId" name="LoginId">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-3 col-md-2">
                                    <b>Password:</b>
                                </div>
                                <div class="col-sm-4 col-md-3">
                                    <div class="input-group">
                                        <span class="input-group-addon">*</span>
                                        <input type="text" class="form-control input-sm" placeholder="Password" name="Password">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-3 col-md-2"></div>
                                <div class="col-sm-4 col-md-3">
                                    <button class="form-control btn-sm btn-primary" type="submit">Login</button>
                                    </div>
                                </div>
                                <div class="row">
                                <div class="col-sm-12">
                                    <p>${SucessMsg}</p>
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            </div>


    </body>
    <script type="text/javascript" src='<spring:url value=" /resources/js/jquery.min.js"/>'></script>
    <script type="text/javascript" src=' <spring:url value="/resources/js/bootstrap.min.js"/>'></script>
</html>

我把我的ccs文件作为
 resource folder having css and js

我不知道我错在哪里,我的页面没有css加载,当我查看页面源并点击css链接时,它显示资源未找到

请检查出现了什么问题。

2 个答案:

答案 0 :(得分:1)

您应该将资源文件夹从webapp移动到WebContent,这肯定是打包到webapp的Web内容文件夹。

- WebContent
     - META-INF
     - resources
          - theme
               ...
     - WEB-INF

答案 1 :(得分:0)

你的路径应该是

<link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/theme/css/bootstrap.min.css" />'>
<link type="text/css"  rel="stylesheet" href='<spring:url value="/resources/theme/css/loginCSS.css" />'>

请添加“/ theme”。

希望这对你有所帮助。