1
我有一個帶有struts2框架的Java web應用程序。在我的index.jsp
文件中,我鏈接了CSS文件,但它並沒有顯示在我的頁面中,並在Firebug
的Error 404: not found
顯示中顯示。我測試了一個沒有Struts的應用程序,一切都很好。但是當我添加的struts2庫和配置struts.xml
和web.xml
文件,CSS不顯示:( 這裏是我的index.jsp:無法在Struts2中應用外部CSS
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="styles/main.css" rel="stylesheet" type="text/css"/>
</head>
當然,我想補充<%@ taglib prefix="s" uri="/struts-tags" %>
,並試圖在HREF <s:url>
,但不要」看不到任何效果 這裏是web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<display-name>HotelSystem</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
,這裏是我的struts.xml中的一部分:
<package name="default" namespace="/" extends="struts-default">
<action name="index.jsp" class="Actions.Test">
<result name="success">/index.jsp</result>
</action>
</package>
備註:Action.Test
是一項測試操作,並始終返回成功。
永遠不要寫*我真的需要儘快解決這個問題。如果你真的想*快速解決問題,或者根本解決它們,請再次幫助我* –
使用Firebug,您可以嘗試從生成的HTML中打開CSS。嘗試一下,看看最終的路徑。這將是錯誤的,你會發現如何;你可能需要在'styles /'之前添加一個斜線。 –