While using Eclipse to develop a website where Servlet sends data to JSP, I encountered an issue. Despite modifying the data in the Servlet, it continued to send outdated information to the JSP page. I attempted the following options:
Menu - Project - clean (Click this option if Build Automatically is not used)
Menu - Project - Project Build Automatically (Check this option)
I also tried restarting and cleaning the Tomcat server.
Here is an example:
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("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;
}
}}
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
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
<!-- JavaScript and HTML code -->
When I made changes inside ProductModel.java as shown above, the results were still incorrect. Please assist me in resolving this issue. Thank you.