2016-09-06 60 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" />'> 

请添加 “/主题”。

希望这对你有所帮助。