Updated: I am Sending data through a jquery as shown below.
<button onclick="call()">Order</button>
<button onclick="call()">Order</button>
<script>
function call(){
window.location.href = "hotel?resName="+$(event.target).parent().siblings().find('.shop-name').text();
}
</script>
Those
<buttons>
have their respected siblings which contains adiv
withclass="shop-name"
My Servlet Code
@WebServlet(name = "hotel", urlPatterns = {"/hotel"}) //servlet name
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try {
if(request.getParameter("resName") != null){
HttpSession session = request.getSession();
fetchFoodList fetchFL = new fetchFoodList(session);
ArrayList<foods> foodList = fetchFL.getAllFoods(request.getParameter("resName"));
request.setAttribute("foodList", foodList);
request.getRequestDispatcher("hotel.jsp").forward(request, response);
}
}catch(Exception e){
System.out.println(e);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
I am getting
ArrayList<foods>
from another java class and it's returning a value.
hotel.jsp here I need to come from servlet (some part of code)
<%
System.out.println("In JSP"); //It's printing in output console
ArrayList<foods> foodList = (ArrayList<foods>)request.getAttribute("foodList");
System.out.println(foodList); //It's also printing [Model.foods@6659e940]
for(foods food: foodList){
%>
<div class="foodlist-outer">
<div class="foodlist-inner">
<div class="img-container">
<div class="img-wrapper">
<div class="img-div"></div>
<img src="images/side-img1.webp" alt="">
</div>
</div>
<div type="veg" class="logo-container">
<div class="logo"></div>
</div>
<div class="food-details-container">
<div class="food-details-inner">
<div class="food-details-wrapper">
<h4 class="heading food-name"><%= food.getFoodName() %></h4>
<div class="cost">
<span>$<%= food.getFoodCost() %></span>
</div>
</div>
<div class="order-btn-container">
<div class="order-btn">
<input type="button" value="-" class="negative">
<span class="add txt">Add</span>
<input type="button" class="qty add" value="">
<input type="button" value="+" class="positive">
</div>
<span class="customize"></span>
</div>
</div>
<p class="description"><%= food.getFoodDescription() %></p>
</div>
</div>
</div>
<%
}
%>
Finally, All the values are computing and server is successfully sending ArrayList<foods>
to JSP. It has been confirmed by println()
statements but the hotel.jsp
is not at all loading...
Thank You!!!