2016-09-06 3 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> 

Я разместил свой файл c¯cs в
resource folder having css and js

Я не знаю, где я ошибаюсь, моя страница загружается без CSS и когда я иду, чтобы просмотреть исходный код страницы и нажмите на ссылку CSS так ли он показывает Ресурс не найден.

Пожалуйста, проверьте, что не так.

ответ

1

Вы должны переместить папку ресурсов из webapp в WebContent, что является уверенностью в папке веб-содержимого, которая упакована в webapp.

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

ok давайте попробуем это –

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

Пожалуйста, добавьте "/ тему".

Надеюсь, это поможет вам.

Смежные вопросы