1.classNotFound:这个时候一般考虑web.xml文件的配置。看 <servlet-class></servlet-class>的内容,按住Ctrl键,看是否能跳到你写的servlet类中,若不能,则一定是你的类名全路径弄错了(今天我的就是这样,我把两个servllet的源文件从之前的包下,转移到其他包下,(因为之前没有按分包规则分包,后来又转移了源文件))。
2.今天在做Ajax异步请求时,遇见了个问题,附上代码如下:
$(function(){ $("#username").blur(function(){ var inusername = $(this).val(); if(inusername.match("^[a-zA-Z0-9]{4,8}$")){ $("#userspan").html(""); $.ajax({ type:"POST", url:"${pageContext.request.contextPath}/yibu", data:"username="+inusername, success:function(data){ $("#userspan").html(data); } }); }else{ $("#userspan").html("用户名必须是字母或数字,4到8位"); } }); }); <tr> <th align="center">用户名</th> <th align="center"> <input type="text" name="username" id="username" > <font style="color:red">${errusername}</font> </th> <td><span id="userspan" style="color:red"></span> </td> </tr>
在离焦事件发生后,前段一直报错:“$”未定义: 此时:我要做的有两件事:
1.看看是否引入jQuery的外部js包。
2.看看是否是因为ID不匹配等的一些低级错误的原因。
可当我排除这两个原因后,还是报错 (懵逼了一个上午),在这期间,我在Ajax走的那个servlet中打上断点,发现根本就没进去。后来,我才反应过来:因为我在项目中配置了过滤器,并且在web.xml中配置的是/*,他吧所有的URL都给过滤了。后来我在filter中做了个判断。让其外部js和图片的uri全部放行即可。
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String path = request.getRequestURI().substring(request.getContextPath().length()); if(path.equals("/index.jsp")||path.equals("/chaxunyourself.jsp") ||path.equals("/login.jsp")||path.equals("/zhuce.jsp")||path.equals("/login") ||path.equals("/zhuce")||path.equals("/chaxunyouserlf")||path.equals("/checkImgServlet") ||path.equals("/image/259097_3_0_0_560_0.jpg")||path.equals("/image/invisible.png") ||path.equals("/image/visible.png")||path.equals("/image/9c6aea464772177355a7c4b1e0be753e.png") ||path.equals("/image/404.jpg")||path.equals("/js/address.js")||path.equals("/js/chaxun.js") ||path.equals("/js/liandong.js")||path.equals("/js/login.js.js")||path.equals("/js/zhuce.js") ||path.equals("/yibu")||path.equals("/js/jquery-1.8.3.js")){ chain.doFilter(request, response); return; }||path.equals("/image/259097_3_0_0_560_0.jpg")||path.equals("/image/invisible.png") ||path.equals("/image/visible.png")||path.equals("/image/9c6aea464772177355a7c4b1e0be753e.png") ||path.equals("/image/404.jpg")||path.equals("/js/address.js")||path.equals("/js/chaxun.js") ||path.equals("/js/liandong.js")||path.equals("/js/login.js.js")||path.equals("/js/zhuce.js") ||path.equals("/yibu")||path.equals("/js/jquery-1.8.3.js")){ chain.doFilter(request, response); return; }