Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 将数据传递给servlet_Jsp_Servlets_Attributes - Fatal编程技术网

Jsp 将数据传递给servlet

Jsp 将数据传递给servlet,jsp,servlets,attributes,Jsp,Servlets,Attributes,我有一个带有几个字段的jsp页面。我需要在servlet中使用其中一些字段来获取汽车的详细信息。这是jsp页面中的表单: <form method="post" action="Update"> <table id="centerTable" width="600"> <tr> &l

我有一个带有几个字段的jsp页面。我需要在servlet中使用其中一些字段来获取汽车的详细信息。这是jsp页面中的表单:

<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");
}