Jsp 将数据传递给servlet
我有一个带有几个字段的jsp页面。我需要在servlet中使用其中一些字段来获取汽车的详细信息。这是jsp页面中的表单:Jsp 将数据传递给servlet,jsp,servlets,attributes,Jsp,Servlets,Attributes,我有一个带有几个字段的jsp页面。我需要在servlet中使用其中一些字段来获取汽车的详细信息。这是jsp页面中的表单: <form method="post" action="Update"> <table id="centerTable" width="600"> <tr> &l
<form method="post" action="Update">
<table id="centerTable" width="600">
<tr>
<th><h5>Car ID</h5></th>
<th><h5>Car Brand</h5></th>
</tr>
<tr>
<td>${bookedCar.id}</td>
<td>${bookedCar.carbrand}</td>
</tr>
</table>
</br></br>
<p class="submit"><input type="submit" value="Cancel Booking"></p>
</form>
首先需要在表单submit中发送信息,因此需要使用输入标记发送此信息,以便以以下方式更改表:
<form method="post" action="Update">
<table id="centerTable" width="600">
<tr>
<th><h5>Car ID</h5></th>
<th><h5>Car Brand</h5></th>
</tr>
<tr>
<td><input type="text" name="bookedCarId" value="${bookedCar.id}" readonly/></td>
<td><input type="text" name="bookedCar" value="${bookedCar.carbrand}" readonly/></td>
</tr>
</table>
</br></br>
<p class="submit"><input type="submit" value="Cancel Booking"></p>
</form>
正如您看到的,此方法获取请求中发送的字符串参数,使用此信息,您可以获取car对象,或者您可以将此对象存储为会话对象的属性,以便在下一个请求中可以获取此对象
<form method="post" action="Update">
<table id="centerTable" width="600">
<tr>
<th><h5>Car ID</h5></th>
<th><h5>Car Brand</h5></th>
</tr>
<tr>
<td><input type="text" name="bookedCarId" value="${bookedCar.id}" readonly/></td>
<td><input type="text" name="bookedCar" value="${bookedCar.carbrand}" readonly/></td>
</tr>
</table>
</br></br>
<p class="submit"><input type="submit" value="Cancel Booking"></p>
</form>
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String myCar = request.getParameter("bookedCar");
String carID = request.getParameter("bookedCarId");
}