gpt4 book ai didi

java - 无法链接 CSS 和图像

转载 作者:行者123 更新时间:2023-11-29 03:40:54 26 4
gpt4 key购买 nike

我正在开发 Spring、Hibernate、JSP 应用程序。我正在尝试显示来 self 的 JSP 页面的图像。图像未显示在浏览器上。我也无法将我的 CSS 链接到 JSP 页面。

我的 JSP 页面是:

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body id="page1">
<div class="headerlogo" align="center"><a href=""><img src="images/Logo1.png" alt="" /></a></div>
<div align="center">
<h1><spring:message code="header.title"/></h1>
Language :
<a href="?lang=en_US">English</a>|
<a href="?lang=sp_SP">Spanish</a>

<h3>
<a href="home"><spring:message code="header.gotohome" /> </a>
</h3>
</div>
</body>
</html>

我已经设置了

<http pattern="/images/**" security="none" />
<http pattern="/css/**" security="none" />

我的图片和 CSS 文件夹

我的 Spring Security xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 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-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">


<http pattern="/images/**" security="none" />
<http pattern="/css/**" security="none" />

<http auto-config="true" use-expressions="true">

<intercept-url pattern="/admin*" access="hasRole('SYS_ADMIN')" />

<form-login login-page="/login" default-target-url="/role-check"
authentication-failure-url="/login?error=true" />
<logout logout-success-url="/login" />

</http>

<authentication-manager>
<authentication-provider>

<jdbc-user-service data-source-ref="fmsDataSource"
users-by-username-query="select USERNAME,PASSWORD, 'true' as enabled from users where USERNAME=?"
authorities-by-username-query="select u.USERNAME, ur.AUTHORITY from users u, user_roles ur where u.USER_ID = ur.USER_ID and u.USERNAME =? " />
</authentication-provider>
</authentication-manager>
</beans:beans>

最佳答案

我通过在 web.xml 中添加以下映射解决了这个问题文件

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>

同时添加 <%=request.getContextPath()%>在图像 src url 中。喜欢<img src="<%=request.getContextPath()%>/images/logo.png" />

关于java - 无法链接 CSS 和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13221421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com