慕粉4016800
2018-01-09 13:27
严重: Servlet.service() for servlet [SearchServlet] in context with path [/ajax_autocomplete] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
.......
package imooc.ajaxautocomplete.search; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; public class SearchServlet extends HttpServlet { static List<String> datas=new ArrayList<String>(); static{ datas.add("ajax"); datas.add("ajax操作"); datas.add("ajax基础教程"); datas.add("boolean"); datas.add("CoCo"); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); //首先获得客户端发送来的数据keyword String keyword=request.getParameter("keyword"); //获得关键字之后进行处理,得到关联数据 List<String> listData=getData(keyword); //返回json格式 response.getWriter().write(JSONArray.fromObject(listData).toString()); } //获得关联数据的方法 public List<String> getData(String keyword){ List<String> list=new ArrayList<String>(); for(String data:datas){ if(data.contains(keyword)){ list.add(data); } } return list; } }
------------------------------------
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>SearchServlet</servlet-name> <servlet-class>imooc.ajaxautocomplete.search.SearchServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SearchServlet</servlet-name> <url-pattern>/search</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
报错信息:
java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
说明依赖包没找到。
Servlet+Ajax实现搜索框智能提示
37805 学习 · 146 问题
相似问题
回答 3
回答 1