Javascript spring mvc应用程序中链接资源的正确方法
我在SpringMVC应用程序中使用jQueryUI。我在spring中给出了mvc-dispatcher-servlet.xmlJavascript spring mvc应用程序中链接资源的正确方法,javascript,css,jquery-ui,jsp,spring-mvc,Javascript,Css,Jquery Ui,Jsp,Spring Mvc,我在SpringMVC应用程序中使用jQueryUI。我在spring中给出了mvc-dispatcher-servlet.xml <mvc:resources mapping="/resources/**" location="/resources/jqueryUI/" /> 我的目录结构如下 在我的jsp中,我将它们称为 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %
<mvc:resources mapping="/resources/**" location="/resources/jqueryUI/" />
我的目录结构如下
在我的jsp中,我将它们称为
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page session="false" %>
<html>
<head>
<script src="/resources/external/jquery/jquery.js"></script>
<script src="/resources/jquery-ui.js"></script>
<link href="/resources/jquery-ui.css" rel="stylesheet">
<script>
$(function() {
alert('function called');
$("#datepicker").datepicker();
});
</script>
</head>
<body>
<div align="center">
<form:form action="register" method="post" commandName="productViewModel">
<table border="0">
<tr>
<td colspan="2" align="center"><h2>Release Registration</h2></td>
</tr>
<tr>
<td>Product Name:</td>
<td><form:input path="name"/></td>
</tr>
<tr>
<td>Version:</td>
<td><form:input path="version"/></td>
</tr>
<tr>
<td>Tag Id:</td>
<td><form:input path="tagId"/></td>
</tr>
<tr>
<td>Release Date:</td>
<td><form:input path="releaseDate"/></td>
<!-- Datepicker -->
<td> <p>Date: <input type="text" id="datepicker"></p></td>
</tr>
<tr>
<td>Setup:</td>
<td><form:input path="setup"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Save" /></td>
</tr>
</table>
</form:form>
</div>
</body>
</html>
$(函数(){
警报('调用函数');
$(“#日期选择器”).datepicker();
});
发布注册
产品名称:
版本:
标记Id:
发行日期:
日期:
设置:
但是当我把那个页面放进去的时候,甚至都没有加载。但是当我离开的时候
<mvc:resources mapping="/resources/**" location="/resources/jqueryUI/" />
页面加载正确,但日期选择器不工作。
基本上,我需要知道在SpringMVC应用程序的jsp中链接资源(js/css)的正确方法是什么。
非常感谢你的帮助
谢谢大家! 如果您使用的是tomcat,那么您可以使用来为资源提供服务 web.xml:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
谢谢Braj。这对tomcat真的很有效。希望这对其他人也有帮助。
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel=stylesheet href="<c:url value='/resources/jquery-ui.css'/>"
type="text/css" />