问题描述
附件test.zip是我的工程大家帮忙看看这个jsp文件中为何引入不到jquery库,目录结构如我上传的图片 请求到这个页面后报: SCRIPT5007: 属性“$”的值为 null、未定义或不是 Function 对象 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ alert("index"); }); </script> </head> <body> index<br> </body> </html>
解决方案
web.xml中这段配置有问题:<servlet-mapping><servlet-name>example</servlet-name><url-pattern>/</url-pattern></servlet-mapping>找个简单的SpringMVC的demo,跟这上面进行配置。跟开涛学SpringMVChttp://www.iteye.com/blogs/subjects/kaitao-springmvc
解决方案二:
修改你的配置文件example-servlet.xml 加上红色部分即可<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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"> <!-- 指定spring mvc controllerr的扫描 --> <context:component-scan base-package="com.yulin.spring.mvc"/> <mvc:annotation-driven/> <mvc:default-servlet-handler/>http://jinnianshilongnian.iteye.com/blog/1423971