如何映射css和js文件从jsp文件在春天mvc [英] how to map css and js file from jsp file in spring mvc

查看:186
本文介绍了如何映射css和js文件从jsp文件在春天mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring mvc的新手。我想在jsp中添加css和js文件。它是一个spring mvc框架。
这是我的spring-dispatcher-servlet.xml代码

I am new to Spring mvc. I want to add css and js files in jsp. It's a spring mvc framework. This is my spring-dispatcher-servlet.xml code

<mvc:annotation-driven />
    <mvc:resources location="/resources/**" mapping="/css/**"/>

SpringDemo是我的项目名称文件夹。我保持我的文件在
SpringDemo / WebContent / resources / css和在同一位置我保持我的js文件也
SpringDemo / WebContent / resources / js

SpringDemo is my project name folder. I keep my file in SpringDemo/WebContent/resources/css and in the same location i keep my js file also SpringDemo/WebContent/resources/js

以下代码是名为RegistrationForm.jsp的jsp文件

Below code is jsp file called RegistrationForm.jsp

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    <link href="WebContent/resources/css/style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/SpringDemo/js/jquery.min.js"></script>


推荐答案

看起来你的资源映射不正确,你的css和js文件在/ resources文件夹下?那么映射应为

Well it looks like your resource mapping is not correct, your css and js files are under "/resources" folder right? then the mapping should be

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

视图中包含的元素在stackoverflow本身中已经多次回答。您可以参考无法使用像css / js in spring mvc
如何在JSP中使用spring MVC添加js和CSS

The inclusion of the elements in the view have been answered multiple times in stackoverflow itself. You can refer unable to use resources like css/js in spring mvc or How to include js and CSS in JSP with spring MVC

这篇关于如何映射css和js文件从jsp文件在春天mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆