I have the following situation:
There is my jsp file
<html>
<head>
<title>car.by</title>
</head>
<body>
<form method="get" action="${pageContext.request.contextPath}/editServlet">
<button type="submit">Редактировать(для админа)</button>
</form>
<form method="get" action="${pageContext.request.contextPath}/">
<button type="submit">Выйти</button>
</form>
<form method="get" action="${pageContext.request.contextPath}/">
<tr>
Марка <br>
Коробка передач <br>
Логин: <br>
<button type="submit">Показать</button> <br>
</tr>
</form>
<jsp:useBean id="cars" scope="request" type="java.util.List"/>
<c:forEach items="${cars}" var="car" varStatus="status">
<tr>
<img SRC=${car.c_photo} width="250" height="250"> <br>
Модель:<td>${car.c_model}</td><br>
Цена за день:<td>${car.c_price}</td><br>
Скидка:<td>${car.p_sale}</td><br>
Производитель:<td>${car.c_producer}</td><br>
Коробка передач:<td>${car.c_transmission}</td><br>
Место нахождения:<td>${car.c_owner}</td><br>
<form method="get" action="${pageContext.request.contextPath}/reservationServlet">
<button style="background-color: black" type="submit">Заказать</button>
</form>
</tr>
</c:forEach>
</body>
</html>
As you can see, here I have a list of forms. Each form has button. I don’t understand, how can I pass for example the car.c_model variable value from the jsp to servlet. Here is my servlet:
@WebServlet("/mainServlet")
public class MainServlet extends HttpServlet{
private CarManager carManager = new CarManager();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
List<Car> cars = carManager.getCarInfo();
req.setAttribute("cars", cars);
RequestDispatcher dispatcher = req.getRequestDispatcher("MainPage.jsp");
dispatcher.forward(req, resp);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}
I will appreciate any help, thanks in advance!