This code snippet is from my CustomerController
servlet.
@WebServlet("/CustomerController")
/*
.
.
.
*/
if(request.getParameter("operation").equalsIgnoreCase("search-customer")) {
CustomerDAO customerDAO = new CustomerDAO();
Customer customer = customerDAO.searchCustomer(Integer.parseInt(request.getParameter("customer_id")));
request.setAttribute("Customer-Result", customer);
RequestDispatcher requestDispatcher;
requestDispatcher = request.getRequestDispatcher("/search-results.jsp");
requestDispatcher.forward(request, response);
}
Instead of redirecting to search-results.jsp
so as to print the result of the search, the results are printed on the servlet's (CustomerController) url itself.
Refer to the image.
search-results.jsp
<%@page import="com.servlet.Customer"%>
<!DOCTYPE html>
<html>
<body>
Customer Found :
<%
Customer customer = (Customer) request.getAttribute("Customer-Result");
out.println(customer.getCustomer_name());
%>
</body>
</html>
What is wrong ?