The jsp file under WEB-INF imports the js file in the js folder under the webapp file
As shown in the following figure: Import My.js file in empListPage.jsp
Picture:
The code in empListPage.jsp is as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/js/My.js"></script></head>
<body>
<a href="" id="update">修改</a>
</body>
</html>
The code in My.js is as follows:
$(function() {
$('#update')
.click(
function() {
var truthBeTold = window.confirm("单击“确定”继续。单击“取消”停止。");
if (truthBeTold) {
window.alert("点击了确定");
} else {
window.alert("再见啦!取消成功");
}
})
})
The code in springmvc.xml is as follows:
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
<!--
配置用于静态资源的请求处理,两个标签结合使用<br>
因为,如果单独配置了<mvc:default-servlet-handler/>
会导致@RequestMapping注解不能够使用<br>
所以,需要两个注解一起使用<br>
default-servlet-handler标签来自于DefaultServlertHttpRequestHandler.
他会对所有的DispatherServlert进行过滤筛选。
如果发现没有映射的请求,则交给tomacat服务器处理。
如果发现有映射请求,则交给DispatherServlet处理
-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
</beans>