无法链接CSS和图像

无法链接CSS和图像

本文介绍了无法链接CSS和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Spring,Hibernate,JSP应用程序。我试图显示从我的JSP页面的图像。图像不显示在浏览器上。我也无法将我的CSS链接到JSP页面。

I am working on a Spring, Hibernate, JSP application. I am trying to display an image from my JSP page. The image not displayed on the browser. I am also not able to link my CSS into JSP page.

我的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文件夹

for my images and CSS folders

我的Spring Security xml是:

My Spring Security xml is:

<?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>


推荐答案

我已经解决了这个问题, code> web.xml 文件

I have resolved the issue by adding following mapping in web.xml file

<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()%> ; in image src url。
< img src =<%= request.getContextPath()%> /images/logo.png/>

and also by adding <%=request.getContextPath()%> in image src url.Like <img src="<%=request.getContextPath()%>/images/logo.png" />

这篇关于无法链接CSS和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:22