Java Servlet 更改后 Web 内容未更新

Web content is not updated after change in Java Servlet

我使用 Eclipse 创建了一个网站,其中 Servlet 将数据发送到 jsp。但是我不知道为什么我要更改 Servlet 中的数据。它仍然将旧数据发送到 jsp。即使我尝试了这些选项..

菜单 - 项目 - 清理(如果不使用自动构建,请单击此选项)

菜单-项目-项目自动构建(勾选这个选项)

我还重新启动并清理了 Tomcat 服务器

示例如下:

Product.java

            public class Product {
            private String id;
            private String name;
            private long price;
            public String getId() {
                return id;
            }
            public void setId(String id) {
                this.id = id;
            }
            public String getName() {
                return name;
            }
            public void setName(String name) {
                this.name = name;
            }
            public long getPrice() {
                return price;
            }
            public void setPrice(long price) {
                this.price = price;
            }
            public Product(String id, String name, long price) {
                super();
                this.id = id;
                this.name = name;
                this.price = price;
            }
        }

ProductModel.java

        public class ProductModel {
        public Product find() {
            return new Product("p0x","name x",700);     // change to return new Product("www","aaa",1000);  
        }
        public List<Product> findAll()
        {List<Product> result= new ArrayList<Product>();
        result.add(new Product("p01","name 1",100));// change to result.add(new Product("xxx","yyy",100));
        result.add(new Product("p04","name 2",200));
        result.add(new Product("p037","name 3",300));
        return result;
            }
        }}
  }

ProductController.java

@WebServlet("/urlaccess")
                public class ProductController extends HttpServlet {
                    private static final long serialVersionUID = 1L;

                    /**
                     * @see HttpServlet#HttpServlet()
                     */
                    public ProductController() {
                        super();
                        // TODO Auto-generated constructor stub
                    }

                    /**
                     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
                     */
                    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                        // TODO Auto-generated method stub
                //      response.getWriter().append("Served at: ").append(request.getContextPath());
                        PrintWriter out= response.getWriter();
                        Gson gson= new Gson();
                        ProductModel productModel= new ProductModel();
                        String action = request.getParameter("action");
                        if(action.equalsIgnoreCase("demo1"))
                        {
                            out.print(gson.toJson(productModel.find()));
                            out.flush();
                            out.close();
                        }
                        else if (action.equalsIgnoreCase("demo2"))
                        {
                            out.print(gson.toJson(productModel.findAll()));
                            out.flush();
                            out.close();
                        }
                    }

                    /**
                     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
                     */
                    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                        // TODO Auto-generated method stub
                        doGet(request, response);
                    }

                }

index.jsp

            <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>
            <!DOCTYPE html>
            <html>
            <head>
            <meta charset="ISO-8859-1">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
            <title>Insert title here</title>
            <script type="text/javascript">
            $(document).ready(function(){
                $('#button2').click(function(){
                    $.ajax({
                        type:'GET',
                        url:'urlaccess?action=demo2',
                        header:{
                            Accept: "application/json; charset=utf-8",
                            "Content-Type":"application/json; charset=utf-8"
                            },
                    success:function (da){
                        //var product= $.parseJSON(result);
                        var listproducts= $.parseJSON(da);
                        var s='';
                        for( var i=0; i<listproducts.length;i++)
                            {s+='ID:'+ listproducts[i].id+'<br>Name:'+listproducts[i].name+'<br>Price:'+listproducts[i].price+'<br>==========<br>';}

                            document.getElementById('result2').innerHTML=s;
                //      alert(product.id);
                    }
                    })
                });

                $('#button1').click(function(){
                    $.ajax({
                        type:'GET',
                        url:'urlaccess?action=demo1',
                        header:{
                            Accept: "application/json; charset=utf-8",
                            "Content-Type":"application/json; charset=utf-8"
                            },
                    success:function (data){
                        var product= $.parseJSON(data);
                        //var listproducts= $.parseJSON(result);
                        //var s='';
                        //for( var i=0; i<listproducts.length;i++)
                        //  {s+='ID:'+ listproducts[i].id+'<br>Name:'+listproducts[i].name+'<br>Price:'+listproducts[i].price+'<br>==========<br>';}
                    //document.getElementById('result2').innerHTML=s;
                        alert(product.id);
                        document.getElementById('result1').innerHTML=product.id;
                    }
                    })
                });


            })
            </script>

            </head>
            <body>
            <h1>JSON to JSP</h1>
            <fieldset>
            <legend>Demo1 </legend>
            <input type="button" value="Display Object" id="button1"> <br>
            <div id="result1"></div>
            </fieldset>
            <fieldset>
            <legend>Demo2 </legend>
            <input type="button" value="Display List Object" id="button2"> <br>
            <div id="result2"></div>
            </fieldset>
            </body>
            </html>

当我把里面的ProductModel.java改成

     public class ProductModel {
    public Product find() {
        return new Product("www","aaa",1000);  
    }
    public List<Product> findAll()
    {List<Product> result= new ArrayList<Product>();
    result.add(new Product("xxx","yyy",100));
    result.add(new Product("p04","name 2",200));
    result.add(new Product("p037","name 3",300));
    return result;
        }
    }}
    }

还是这样显示结果 请帮我。谢谢

谢谢@rhenesys。我想分享给每个有同样问题的人。你应该换一个浏览器。比如我改成Chrome浏览器。它对我有用