系统找不到指定路径?是浏览器没有清除缓存吗?

系统找不到指定路径?是浏览器没有清除缓存吗?

警告: 异常处理加载程序[WebappLoader[/ajax]]后台进程

java.lang.IllegalStateException: java.io.FileNotFoundException: D:\apache-tomcat-8.5.53\webapps\ajax\WEB-INF\lib\fastjson-1.2.53.jar (系统找不到指定的路径。)


package com.imooc.ajax;


public class News {


private String title;

private String date;

private String source;

private String content;

public News() {

}

public News(String title, String date, String source, String content) {

super();

this.title = title;

this.date = date;

this.source = source;

this.content = content;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getDate() {

return date;

}

public void setDate(String date) {

this.date = date;

}

public String getSource() {

return source;

}

public void setSource(String source) {

this.source = source;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

}



package com.imooc.ajax;


import java.io.IOException;

import java.util.ArrayList;

import java.util.List;


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 com.alibaba.fastjson.JSON;


/**

 * Servlet implementation class NewsListServlet

 */

@WebServlet("/news_list")

public class NewsListServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

       

    /**

     * @see HttpServlet#HttpServlet()

     */

    public NewsListServlet() {

        super();

        // TODO Auto-generated constructor stub

    }


/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

try {

Thread.sleep(5000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

List list = new ArrayList();

list.add(new News("TIOBE:2018年5月份全球编程语言排行榜" , "2018-5-1" , "TIOBE" , "..."));

list.add(new News("TIOBE:2018年6月份全球编程语言排行榜" , "2018-6-1" , "TIOBE" , "..."));

list.add(new News("TIOBE:2018年7月份全球编程语言排行榜" , "2018-7-1" , "TIOBE" , "..."));

list.add(new News("TIOBE:2018年8月份全球编程语言排行榜" , "2018-8-1" , "TIOBE" , "..."));

String json = JSON.toJSONString(list); //json是fastjson为提供的java对象

System.out.println(json);

response.setContentType("text/html;charset=utf-8");

response.getWriter().println(json);


}



<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<div id="container">

</div>

<script type="text/javascript">

//1.创建XmlHttpRequest

var xmlhttp;

if(window.XMLHttpRequest){

xmlhttp = new XMLHttpRequest();

}else{

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

//2.发送Ajax请求

//true表示异步执行,false表示同步执行

xmlhttp.open("GET" , "/ajax/news_list" , false);

xmlhttp.send();

console.log("请求发送完成!");

if(xmlhttp.readyState == 4 && xmlhttp.status == 200){

var text = xmlhttp.responseText;

console.log(text);

var json = JSON.parse(text); //json是javascript内置的对象

console.log(json);

var html = "";

for(var i=0; i<json.length; i++){

var news = json[i];

html = html + "<h1>" + news.title + "</h1>";

html = html + "<h2>" + news.date + "&nbsp;" + news.source + "&nbsp" + news.content + "</h2>";

html = html + "<hr/>";

document.getElementById("container").innerHTML = html;

}

}

//3.处理服务器响应

/* xmlhttp.onreadystatechange = function(){

if(xmlhttp.readyState == 4 && xmlhttp.status == 200){

var text = xmlhttp.responseText;

console.log(text);

var json = JSON.parse(text); //json是javascript内置的对象

console.log(json);

var html = "";

for(var i=0; i<json.length; i++){

var news = json[i];

html = html + "<h1>" + news.title + "</h1>";

html = html + "<h2>" + news.date + "&nbsp;" + news.source + "&nbsp" + news.content + "</h2>";

html = html + "<hr/>";

document.getElementById("container").innerHTML = html;

}

}

}*/

</script>

</body>

</html>


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,测试同学的代码是正确的。如下所示:

http://img1.sycdn.imooc.com//climg/5e8d5082094a39f406760465.jpg

同学可以检查一下路径是否正确。课程中的ajax是老师的项目名,如下:

http://img1.sycdn.imooc.com//climg/5e8d548f09edb38b06060150.jpg

如果路径正确,可能是缓存的原因,同学你可以清理一下浏览器缓存以及对eclipse进行clean。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 慕粉1465475474 提问者 #1
    是缓存问题,谢谢老师!
    2020-04-08 21:17:01
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师