css - 无法在 Struts2 中应用外部 CSS

标签 css jsp struts2

我有一个带有 struts2 框架的 Java 网络应用程序。在我的 index.jsp文件,我链接了 CSS 文件,但它没有显示在我的页面和 Error 404: not found显示在 Firebug .我在没有使用 Struts 的情况下测试了一个应用程序,一切正常。但是当我添加 struts2 库和配置时 struts.xmlweb.xml文件,CSS 不显示 :( 这是我的 index.jsp:

<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" %>并尝试了 <s:url>在 href 中,但看不到任何效果。 这是 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是一个测试 Action ,总是返回成功。

最佳答案

您应该将 .css 类型映射到 web.xml 文件中,如下所示!

<filter-mapping>
    <filter-name>expires-filter</filter-name>
    <url-pattern>*.css</url-pattern>
</filter-mapping>

关于css - 无法在 Struts2 中应用外部 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21038957/

相关文章:

java - 无法使用 XML-RPC 上传 WordPress 媒体文件

java - struts2拦截器的问题

java - Struts 2 中的拦截器未正确重定向页面

javascript - 使用按钮调用 javascript 函数

html - CSS 形状过渡 - 左下角

jsp - 导航栏中的推特 Bootstrap 和个人资料/头像图像

java - 如何在 Struts2 中为选择(选择事件)提供单独的操作(在自动完成文本框中使用)

css - Bootstrap 网格高度与屏幕分辨率的百分比

HTML/CSS 图像引用不适用于内联 css

java - JSP session.getAttribute异常错误