2016-09-06 61 views
0

我知道這是一個重複的問題,但我無法通過查看另一個問題的解決方案來解決問題。不過,我已經完成了上一個問題中提到的所有內容。
這就是爲什麼我用我的代碼問這個問題,請看我的代碼有什麼問題。
我的web.xmlSpring MVC Js和css不加載

<?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; 

    } 
} 

我LoginPage

<%@ 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鏈接它它顯示資源未找到

請檢查是否有問題。

回答

1

您應該將資源文件夾從webapp移動到WebContent中,這肯定是打包到webapp的web內容文件夾。

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

好的,讓我試試這個 –

+0

thnaks它的工作。 –

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" />'> 

請添加 「/主題」。

希望這對你有所幫助。