1

我的web应用程序不显示任何静态内容。静态内容与码头和弹簧

  • Spring MVC的
  • Twitter的引导
  • 码头7

生成项目: MVN干净的安装与码头包括

的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_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
    <display-name>Some company</display-name> 
    <welcome-file-list> 
     <welcome-file>list.html</welcome-file> 
    </welcome-file-list> 
    <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

弹簧servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns="http://www.springframework.org/schema/beans" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:annotation-config /> 
    <!-- use this for Spring Jackson JSON support --> 
    <mvc:annotation-driven /> 
    <mvc:default-servlet-handler /> 
    <tx:annotation-driven transaction-manager="transactionManager" /> 
    <jdbc:embedded-database id="dataSource" type="H2" /> 

    <context:component-scan base-package="com.company.config" /> 
    <context:component-scan base-package="com.company.market.dao" /> 
    <context:component-scan base-package="com.company.service.app" /> 
    <context:component-scan base-package="com.company.controller" /> 

    <bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> 
    <bean 
     class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
     <property name="viewResolvers"> 
      <list> 
       <bean 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> 
      </list> 
     </property> 
    </bean> 
</beans> 

hero.jsp新增的.jsp libary否则Twitter的引导的例子,但删除了一些内容

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ page session="false" %> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <title>Bootstrap, from Twitter</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <!-- Le styles --> 
    <link href="../resources/assets/bootstrap/css/bootstrap.css" rel="stylesheet"> 
    <style type="text/css"> 
     body { 
     padding-top: 60px; 
     padding-bottom: 40px; 
     } 
    </style> 
    <link href="../resources/assets/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> 

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> 
    <!--[if lt IE 9]> 
     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 

    <!-- Le fav and touch icons --> 
    <link rel="shortcut icon" href="../resources/assets/bootstrap/ico/favicon.ico"> 
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../resources/assets/bootstrap/ico/apple-touch-icon-144-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../resources/assets/bootstrap/ico/apple-touch-icon-114-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../resources/assets/bootstrap/ico/apple-touch-icon-72-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" href="../resources/assets/bootstrap/ico/apple-touch-icon-57-precomposed.png"> 
    </head> 

    <body> 

    <div class="navbar navbar-fixed-top"> 
     <div class="navbar-inner"> 
     <div class="container"> 
      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      </a> 
      <a class="brand" href="#">Project name</a> 
      <div class="nav-collapse"> 
      <ul class="nav"> 
       <li class="active"><a href="#">Home</a></li> 
       <li><a href="#about">About</a></li> 
       <li><a href="#contact">Contact</a></li> 
      </ul> 
      </div><!--/.nav-collapse --> 
     </div> 
     </div> 
    </div> 

    <div class="container"> 

     <!-- Main hero unit for a primary marketing message or call to action --> 
     <div class="hero-unit"> 
     <h1>Hello, world!</h1> 
     <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p> 
     <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p> 
     </div> 


    </body> 
</html> 

文件夹结构Maven的等。

src 
- main 
    - webapp 
     - WEB-INF 
      -jsp 
      -resources 
       - assets 
        -bootstrap 
         - css 
         - ico 
         - img 
         - js 
     - spring-servlet.xml 
     - web.xml 

当我打开了hero.jsp为hero.html并查看它在浏览器中我看到Twitter的引导工作,但是当我部署它没有什么工作...... 我

发挥各地
<mvc:resources mapping="/resources/**" location="/public-resources/"/> 

,但它没有工作......

如果我看着在HTML文件的来源,当它被部署的链接如为的.css点

http://localhost:8080/resources/assets/bootstrap/css/bootstrap.css 
+2

尝试将资源移动到webapp目录。谢谢 – prashanth 2012-08-10 13:31:11

+0

THX !!我还要将位置从../ resources ...更改为../../resources – Philippxp 2012-08-10 13:42:09

回答

0

尝试移动资源webapp目录是正确的提示。