簡體   English   中英

CSS樣式表在tomcat中不可用

[英]CSS stylesheet not available in tomcat

我在eclipse中創建了一個maven-webapp項目,並希望在.jsp站點上放置一個CSS樣式表,但是我的tomcat總是說“請求的源不可用”。

這是我的.jsp文件(也嘗試將絕對路徑添加到該文件...):

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/src/main/webapp/WEB-INF/pages/index1.css"> <link rel="stylesheet" type="text/css" href="index1.css"> <link rel="stylesheet" type="text/css" href="/WEB-INF/pages/index1.css"><title>Simple Form Demo</title> </head> <body> <h1>test</h1> <h2>Simple Form Demosdds</h2> <div id="ololo" class="container"> <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> Dropdown Example <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#">HTML</a></li> <li><a href="#">CSS</a></li> <li><a href="#">JavaScript</a></li> </ul> </div> </div> <form name="myForm" action="result.jsp" method="post"> <table> <tbody> <tr> <td>First Name:</td> <td><input type="text" name="first" value="" size="50"></td> </tr> <tbody> <tr> <td>Last Name:</td> <td><input type="text" name="last" value="" size="50"></td> </tr> <tbody> <tr> <td>Email:</td> <td><input type="text" name="email" value="" size="50"></td> </tr> <tbody> <tr> <td>Gender:</td> <td><input type="radio" name="gender" value="Male" />Male <input type="radio" name="gender" value="Female" />Female</td> </tr> <tr> <td><select name="state"> <option value="">Choose a state...</option> <option value="IA">Ioaw</option> <option value="IL">Illinois</option> <option value="MO">Missouri</option> <option value="Other">Other</option> </select></td> </tr> </tbody> </table> <input type="reset" value="Clear" name="clear"> <input type="submit" value="Submit" name="submit"> </form> </body> </html> 

這是我的.css文件:

 @CHARSET "ISO-8859-1"; body { background-color: red; } h1 { color: navy; margin-left: 60px; } h2 { size: 220; margin-left: 60px; } #ololo { color: red; } 

當我啟動tomcat 8時,它看起來像這樣: 單擊

當我直接將.css文件導入到firefox中時,它可以工作。

我的結構是這樣的: 單擊

€:web.xml:

 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app> 

mvc-dispatcher-servlet.xml:

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.XXX.XXX.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans> 

好吧,終於我找到了問題。 我必須將mvc:resources映射添加到我的mvc-dispatcher-servlet.xml中。

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <context:component-scan base-package="com.xxx.xxx.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM