2014-03-25 107 views
0

在我的Spring項目時,我的一個控制器有以下幾點看法:不一致的資源在一個Spring項目的映射

login -> /WEB-INF/jsp/acesso/login.jsp 
logout -> /WEB-INF/jsp/acesso/logout.jsp 
start -> /WEB-INF/jsp/acesso/start.jsp 

這些工作幾乎正常,但與此同第一小問題查看(登錄):

當我第一次打電話(也就是當我啓動應用程序時),頁面顯示正確。但是在我從內部呼叫註銷後,我有一個鏈接登錄。當我點擊這個鏈接時,視圖登錄顯示錯誤,不能覆蓋html代碼中包含的任何css文件。

的JSP上述文件是:

的login.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title>HorarioLivre - Login</title> 

    <link href="<c:out value="bootstrap/css/bootstrap.min.css"/>" rel="stylesheet"> 

    <link href="<c:out value="extras/css/signin.css"/>" rel="stylesheet"> 

    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
    </head> 

    <body> 

    <div class="container"> 

    <form class="form-signin" role="form" method="post" action="<c:out value="acesso/doLogin.html"/>"> 
    <h2 class="form-signin-heading">Please sign in</h2> 
    <input type="text" class="form-control" name="username" placeholder="Username" required autofocus> 
    <input type="password" class="form-control" name="password" placeholder="Password" required> 
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> 
    </form> 

    </div> <!-- /container --> 


    <!-- Bootstrap core JavaScript 
    ================================================== --> 
    <!-- Placed at the end of the document so the pages load faster --> 
    </body> 
</html> 

start.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title>HorarioLivre</title> 

    <!-- Bootstrap core CSS --> 
    <link href="<c:out value="../bootstrap/css/bootstrap.min.css"/>" rel="stylesheet"> 

    <!-- Custom styles for this template --> 
    <link href="<c:out value="../extra/css/starter-template.css"/>" rel="stylesheet"> 

    <script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> 

    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
    <![endif]--> 
    </head> 

    <body> 

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> 
     <div class="container"> 
     <div class="navbar-header"> 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
      <span class="sr-only">Toggle navigation</span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      </button> 
      <a class="navbar-brand" href="#">HorarioLivre</a> 
     </div> 
     <div class="collapse navbar-collapse"> 
      <ul class="nav navbar-nav"> 
      <li><a href="#">Eventos</a></li> 
      <li><a href="#">Listar Hor&aacute;rios</a></li> 
      <li><a href="#">Cadastrar Hor&aacute;rios</a></li> 
      <li><a href="#">Usu&aacute;rios</a></li> 
      </ul> 
      <ul class="nav navbar-nav navbar-right"> 
       <li class="dropdown"> 
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">${usuario.primeiroNome} ${usuario.ultimoNome}<b class="caret"></b></a> 
        <ul class="dropdown-menu"> 
        <li><a href="#">Perfil</a></li> 
        <li><a href="#">Configura&ccedil;&otilde;es</a></li> 
        <li><a href="<c:out value="logout.html"/>">Sair</a></li> 
        </ul> 
       </li> 
      </ul> 
     </div><!--/.nav-collapse --> 
     </div> 
    </div> 

    <div class="container"> 

     <div class="starter-template"> 
     </div> 

    </div><!-- /.container --> 


    <!-- Bootstrap core JavaScript 
    ================================================== --> 
    <!-- Placed at the end of the document so the pages load faster --> 
    <script src="<c:out value="../jquery/js/jquery-2.1.0.min.js"/>"></script> 
    <script src="<c:out value="../jquery/js/jquery-ui-1.10.4.custom.min.js"/>"></script> 
    <script src="<c:out value="../bootstrap/js/bootstrap.min.js"/>"></script> 
    </body> 
</html> 

logout.html

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title>Saida do sistema</title> 

    <!-- Bootstrap core CSS --> 
    <link href="<c:out value="../bootstrap/css/bootstrap.min.css"/>" rel="stylesheet"> 

    <!-- Custom styles for this template --> 
    <link href="<c:out value="../extra/css/jumbotron-narrow.css"/>" rel="stylesheet"> 

    <script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> 

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> 
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
    </head> 

    <body> 

    <div class="container"> 
     <div class="header"> 
     <h3 class="text-muted">HorarioLivre</h3> 
     </div> 

     <div class="jumbotron"> 
     <h1>Você saiu do sistema</h1> 
     <p class="lead"></p> 
     <p><a class="btn btn-lg btn-success" href="<c:out value="login.html"/>" role="button">Entrar novamente</a></p> 
     </div> 

     <div class="footer"> 
     <p>Kleber Mota de Oliveira &copy; 2014</p> 
     </div> 

    </div> <!-- /container --> 


    <!-- Bootstrap core JavaScript 
    ================================================== --> 
    <!-- Placed at the end of the document so the pages load faster --> 
    </body> 
</html> 

有人知道如何更正爲這些文件設置映射,工作無所謂它是如何調用的?

PS:我的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>HorarioLivre2</display-name> 

    <welcome-file-list> 
    <welcome-file>acesso/login.html</welcome-file> 
    </welcome-file-list> 

    <servlet> 
    <servlet-name>HorarioLivre2</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>HorarioLivre2</servlet-name> 
    <url-pattern>*.html</url-pattern> 
    </servlet-mapping> 
</web-app> 

HorarioLivre2-servlet.xml中

<?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:tx="http://www.springframework.org/schema/tx" 
     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/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> 

     <context:component-scan base-package="com.horariolivre"/> 
      <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
       <property name="prefix" value="/WEB-INF/jsp/" /> 
       <property name="suffix" value=".jsp" /> 
      </bean> 

     <context:annotation-config> 
      <bean class="com.horariolivre.resources.HibernateConfig"> 
      </bean> 
     </context:annotation-config> 

     <tx:annotation-driven transaction-manager="transactionManager"/> 
</beans> 

回答

0

在你HorarioLivre2-servlet.xml中似乎你有未映射靜態資源。看看這個link看看這是怎麼完成的

+0

我想這不僅僅是,你可以在這個主題中看到:http://stackoverflow.com/questions/22632493/use-of-the-mvcresources-導致一個404錯誤在我的春天應用程序,在那裏我介紹一個問題完全與你說明的鏈接(是的,我已經看到它)中描述的這種方法。 –