[html] view plain copy
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
在springmvc-servlet.xml中的配置:
[html] view plain copy
<mvc:annotation-driven/>
<mvc:resources location="/WEB-INF/resources/js/" mapping="/js/**"></mvc:resources>
项目的目录结构:
如果index.vm中想要引入js目录下的jquery.min.js文件,则需这样写路经:
[html] view plain copy
<head>
<meta charset="UTF-8"/>
<meta charset="r.yuzhua.com"/>
<script type="text/javascript" src="../js/jquery.min.js"></script>
</head>
这样,就能正常引入了。
要加快网页的加载速度,其实有很多方法。减少包含js也是一种优化手段。至于MVC只是一种思考的模式,并不具有加载js的方法。
据我所知,可以借助smarty3来实现减少包含js。
理论指导是使用组合的方式,也就是高内聚,低耦合。
举个例子
在A页面需要用到example.js里面的的方法,那么我可以在A页面这样写
<{include file="example.tpl"}>
然后在example.tpl里面加入
<script src="<{$jsUrl}>example.js" type="text/javascript"></script>
1:首先在script 文件家里面添加这两个js2:其次在html页面添加脚本的引用
例如:
<html>
<body>
<form>
<input type='text' />
</form>
<script src='../script/jquery.validate.min.js'></script>
<script src='../script/jaquery.validate.unobtrusive.min.js'></script>
</body>
</html>
Good Luck! 希望能够帮助到你!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)