繁体   English   中英

Java / Javascript / JSP中的下拉选项

[英]drop down choice in Java/Javascript/JSP

我正在创建一个简单的Web应用程序,用户可以在其中选择要预订的房间。 特别是,我应该有机会让您选择其他类型或房间(例如,我拥有经典房,高级房,豪华房)。 我已为预订客房的其他功能创建了此表格:

<label class="Labeltext" >Name:</label>
            <input type="text" name="name"  style="margin-left: 238px; margin-top: 0px;"/>
                <br><br>
             <label class="Labeltext" >Email:</label>
            <input type="text" name="email"  style="margin-left: 239px; margin-top: 0px;"/>
                <br><br>
            <label class="Labeltext" >Arrival Date:</label>
            <input type="date" name="arrivaldate"  style="margin-left: 180px; margin-top: 0px;"/>
                <br><br>
            <label class="Labeltext"  margin-top: -20px;">Departure Date:</label>
            <input type="date" name="departuredate" style="margin-left: 146px;" />
                <br><br>
            <label class="Labeltext" >Total No. of Persons:</label>
            <input type="text" name="person"  style="margin-left: 100px; margin-top: 0px;"/>
                <br><br>

            <label class="Labeltext" >Total No. of Rooms:</label>
            <input type="text" name="rooms"  style="margin-left: 112px; margin-top: 0px;"/>
            <br><br>

现在我有了这2个数据库:

带有以下参数的HotelBooking:cid,cname,email,到达日期,出发日期,人,房间,评论,状态,id和第二个:酒店:豪华,经典,高级

在您看来,如何在.jsp文件中插入会议室的功能(豪华,经典,高级)? 我已经尝试了一个下拉菜单,但是我不知道要实现它。 (因为我不能使用php解决方案)。 多谢你们。

如果您使用的是EL,请使用:

<select name="room">
                <option value=0>Select one</option>
                    <c:forEach items="${rooms}" var="product">
                        <option value="${product.id}"><c:out value="${product.name}" /> </option>
                    </c:forEach>
                </select> 

“房间”列表包含您的房间类型。 我假设您已经知道如何将它们传递给jsp? 如果不是,您使用Spring还是普通的Servlet?

通过Controller / Servlet提供房间

@WebServlet("/RoomsController")
public class RoomsController extends HttpServlet{

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

        // Create in createListWithRoomTypes() a List with room types so that you can list them as a select list
        request.setAttribute("rooms", createListWithRoomTypes());

        RequestDispatcher rd = request.getRequestDispatcher(forward);
        rd.forward(request, response);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM