我一直在網上搜索,並在我的頭髮上關於如何解決這個問題近3周,但我找不到原因爲什麼我的靜態文件在我的本地Windows中使用tomcat 7在Spring MVC中提供,而不是在我們的Linux(Ubuntu)服務器上。下面我描述我的項目文件的結構和我的所有相關文件:靜態文件在Spring MVC中使用tomcat 7在Windows中,但不在Linux上
web.xml中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>com.bakuparkingaz.util.BakuParkingServletContext</listener-class>
</listener>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
APP-context.xml中:
<tx:annotation-driven />
<context:component-scan base-package="com.bakuparkingaz"/>
<context:property-placeholder location="classpath:db.properties" />
<mvc:resources mapping="/resources/**" location="/resources/"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
AdminController.java:
@Controller
public class AdminController {
/.
@RequestMapping(value = "/admin")
public String admin() {
return "resources/admin/index.html";
}
}
所以,現在當我打電話http://localhost:8080/admin我得到漂亮的風格的頁面,但服務器http://8.8.8.8/project/admin在一個醜陋的styleless html頁面(我已經部署了我的戰爭文件project.war到雄貓WebApp文件夾)的結果。爲什麼我的靜態文件不能在linux服務器上運行?
UPDATE: 管理員/ index.html的:
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/resources/admin/">
<meta charset="utf-8">
<title>BP Admin</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/semantic.min.css">
<link rel="stylesheet" href="css/my.css">
<link rel="stylesheet" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<div class="ui left vertical labeled icon menu sidebar" id="left-menu">
<a class="item">
<i class="home icon"></i>
Home
</a>
</div>
<div class="footer">
<div class="text center"><p>Copyright (c) 2015 - BakuParking</p> </div>
</div>
</div>
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" charset="utf-8"></script>
<script src="js/semantic.min.js"></script>
<script src="js/my.js"></script>
</body>
</html>
上下文路徑不同,也許您可以嘗試在索引的
中添加[https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base)標記html的。 – sp00m謝謝,我正在做你現在提出的建議,但我認爲這只是爲了簡單,我認爲它不會解決問題。 – gdrt