[spring][jsp] css文件问题

发布于 2024-10-19 02:02:56 字数 1774 浏览 1 评论 0原文

我的 JSP 页面上的 .css 文件有问题。

我的页面如下所示:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

...
<link href="test.css" rel="stylesheet" type="text/css">
...

<body>

<div id="header">....

当我在 JBoss5.1 上部署应用程序时,收到一条警告消息:

WARN [PageNotFound] 在名为“appTest1”的 DispatcherServlet 中找不到带有 URI [/appTest1-web/test.css] 的 HTTP 请求的映射

有人知道为什么吗?

添加

<?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>appTest1</display-name>


    <servlet>
        <servlet-name>appTest1</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appTest1</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>
            index.jsp
    </welcome-file>
    </welcome-file-list>

</web-app>

I have problem with .css file on my JSP page.

My page looks like this:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

...
<link href="test.css" rel="stylesheet" type="text/css">
...

<body>

<div id="header">....

When I deploy my application on JBoss5.1 a get a warn message:

WARN [PageNotFound] No mapping found for HTTP request with URI [/appTest1-web/test.css] in DispatcherServlet with name 'appTest1'

Anybody know why?

ADDED

<?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>appTest1</display-name>


    <servlet>
        <servlet-name>appTest1</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appTest1</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>
            index.jsp
    </welcome-file>
    </welcome-file-list>

</web-app>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦忆晨望 2024-10-26 02:02:56

您用来调用此页面的基本 URL 是否是偶然的:/appTest1?

我假设您只是将此页面/控制器放在 /appTest1 下,因此当它在页面上查找任何资源(例如您的 css、任何图像、js 等)时,它会在“/appTest1/your_resource”下查找,

也许该类包含您的控制器有类似 @RequestMapping("appTest1") 的东西吗?或者也许这是一个 JBoss 工件(如果是这样,我不是一个 JBoss 人,所以不能在那里提出想法)。

无论如何,您的 CSS 文件可能应该使用“../test.css”或静态引用(例如:“/static/css/test.css”)进行适当引用,我选择后者。

顺便说一句,在春天,我为非动态内容配置了一个静态目录:

<mvc:resources mapping="/public/**" location="/public/"/>

大型网站还考虑将静态内容放在单独的域下,例如 static.mydomain.com 或 mycontentdomain.net 以避免 cookie 与静态内容一起传递。

希望所有这些都能帮助您找到正确的方向。

Is the base URL that you're using to call this page: /appTest1 by chance?

I assume you simply have placed this page/controller under /appTest1 and thus when it looks for any resource on the page (e.g. your css, any image, js's, etc) it is looking under "/appTest1/your_resource"

Perhaps the class that contains your controller has something like @RequestMapping("appTest1")? or perhaps that's a JBoss artifact (if so, I'm not a JBoss guy, so can't suggest ideas there).

In any case, your CSS file should probably be referenced appropriately with either "../test.css", or the static reference, such as: "/static/css/test.css", I choose the latter.

Incidentally, in spring I configured a static directory for non-dynamic content with:

<mvc:resources mapping="/public/**" location="/public/"/>

Large scale websites also consider putting static content under a separate domain such as static.mydomain.com or mycontentdomain.net to avoid having cookies passed along with static content.

Hope all that helps you get yourself pointed in the right direction.

终陌 2024-10-26 02:02:56

似乎您的 DispatcherServlet 正在尝试处理 test.css。检查您的 web.xml 以查看 * 或 .css 请求是否定向到您的 DispatcherServlet。您应该寻找如下所示的内容。确保将 url 模式限制为您想要定向到调度程序 servlet 的扩展。

<servlet-mapping>
  <servlet>dispatcher</servlet>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

Seems like your DispatcherServlet is trying to process the test.css. Check your web.xml to see if * or .css requests are directed to your DispatcherServlet. You should look for something like below. Make sure to limit the url-pattern to the extensions you want to be directed to the dispatcher servlet.

<servlet-mapping>
  <servlet>dispatcher</servlet>
  <url-pattern>/*</url-pattern>
</servlet-mapping>
愛放△進行李 2024-10-26 02:02:56

我认为您在 xml 中的其他地方犯了错误,但在更高级的重定向中,您可以使用 UrlRewrite 过滤器 http://www. tuckey.org/urlrewrite/

I think you somewhere else in xml make mistake, but in more advanced redirection you can use UrlRewrite filter http://www.tuckey.org/urlrewrite/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文