【发布时间】:2017-09-16 13:11:56
【问题描述】:
`<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href='<c:url value="/resources/css/epds1.css" />' rel='stylesheet'>
<title>FOOD SECURITY CARDS</title>
</head>`[![This is My Jsp Page][ In this Page i need load js ,css,images]][i tried doing from all sources but no use]
----------
**Spring Application config file**
`<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<context:component-scan base-package="com.nic.controller"></context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:annotation-driven />
<mvc:resources location="/resources/**" mapping="/resources/" />`
以上是项目结构。我想知道如何在 Spring JSP 页面中加载所有静态资源。
我尝试从所有来源和不同的方式做:<mvc:resources location="/resources/**" mapping="/resources/" /> <link rel='stylesheet' href='<c:url value="/resources/css/epds1.css" />' /> 但仍然没有为我工作。
【问题讨论】:
-
<link rel='stylesheet' href='<c:url value="/resources/css/epds1.css" />' />像您一样应该可以正常工作。可能还有其他问题,但您需要包含您的 spring 配置和 pom.xml 以找出原因。 -
还要验证你的jsp开头有
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -
是的,我添加了你上面提到的所有代码,但问题仍然存在
-
您能否在问题中添加您在 jsp 中有什么以及 HTML 输出是什么?