Spring项目中资源映射的不一致性

时间:2014-03-25 02:13:56

标签: spring spring-mvc

在我的Spring项目中,我的一个控制器有以下视图:

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

工作得很好,除了第一个视图(登录)的这个小问题:

当我第一次调用它时(也就是说,当我启动应用程序时),页面显示正确。但是在我从内部开始调用logout之后,我有一个登录链接。当我点击此链接时,视图登录显示错误,没有达到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>

1 个答案:

答案 0 :(得分:0)

在您的HorarioLivre2-servlet.xml中,您似乎没有映射静态资源。查看此link以了解如何完成此操作