用的IDEA,已经导入了fastjson包 为什么还是显示500
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import com.alibaba.fastjson.JSON; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; @WebServlet ( "/newslist" ) public class NewsListServlet extends HttpServlet { public NewsListServlet() { } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<News> list = new ArrayList<>(); list.add( new News( "TIOBE:2018年5月份全球编程语言排行榜" , "2018-5-1" , "TIOBE" , "1.java 2.python 3. c" )); list.add( new News( "TIOBE:2018年6月份全球编程语言排行榜" , "2018-6-1" , "TIOBE" , "1.java 2.python 3. c" )); list.add( new News( "TIOBE:2018年7月份全球编程语言排行榜" , "2018-7-1" , "TIOBE" , "1.java 2.python 3. c" )); list.add( new News( "TIOBE:2018年8月份全球编程语言排行榜" , "2018-8-1" , "TIOBE" , "1.java 2.python 3. c" )); String json= JSON.toJSONString(list); System.out.println(json); response.setContentType( "text/html;charset=utf-8" ); response.getWriter().println(json); } } |
Type Exception Report
Message Servlet execution threw an exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSON
NewsListServlet.doGet(NewsListServlet.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.ClassNotFoundException: com.alibaba.fastjson.JSON
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1364)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1185)
NewsListServlet.doGet(NewsListServlet.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧