Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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
Java 在jsp中设置checkox的位置_Java_Mysql_Jsp - Fatal编程技术网

Java 在jsp中设置checkox的位置

Java 在jsp中设置checkox的位置,java,mysql,jsp,Java,Mysql,Jsp,我正在写一个在线预订系统应用程序。用户可以通过复选框选择活动。然后,他们可以接受他们的保留。我的复选框位置有问题,我不知道如何使用“提交”按钮提交这些选中的预订 <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ page import ="java.sql.*" %> <!DOCTYPE html> <html> <head> <meta http

我正在写一个在线预订系统应用程序。用户可以通过复选框选择活动。然后,他们可以接受他们的保留。我的复选框位置有问题,我不知道如何使用“提交”按钮提交这些选中的预订

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>




<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Book Ticket</title>
</head>
<body>
<center>    
<table border="1" width="30%" height="30%">
    <tr><th><font color='#D18603'>Activity ID.</font></th>
        <th><font color='#D18603'>Type</font></th>
        <th><font color='#D18603'>Description</font></th>
        <th><font color='#D18603'>City</font></th>
        <th><font color='#D18603'>Location</font></th>
        <th><font color='#D18603'>Date</font></th>
        <th><font color='#D18603'>Price</font></th>
        <th><font color='#D18603'>Buy</font></th>
    </tr>
    <td><b><font color='#663300'><input type="checkbox" name="ticket"       value=""/></font></td></b>



    <%
        Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
        Connection con =   DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");

        Statement st = con.createStatement();
        ResultSet rs;
        rs = st.executeQuery("select * from activities");
        while (rs.next()) {

            String activityid1 = rs.getString("id");
            String type1 = rs.getString("type");
            String description1 = rs.getString("description");
            String city1 = rs.getString("city");
            String location1 = rs.getString("location");
            String date1 = rs.getString("date");
            String price1 = rs.getString("price");

            out.println("<tr>");
            out.println("<td>" + activityid1 + "</td>");
            out.println("<td>" + type1 + "</td>");
            out.println("<td>" + description1 + "</td>");
            out.println("<td>" + city1 + "</td>");
            out.println("<td>" + location1 + "</td>");
            out.println("<td>" + date1 + "</td>");
            out.println("<td>" + price1 + "</td>");

            out.println("</tr>");

        }


    %>

 </center>
 </table></body>
 <tr>
 <td colspan="10"><input type="submit" value="Submit" /></td>
 <td><input type="reset" value="Reset" /></td>
 </tr> 
 <br><br><a href='logout.jsp'>Log out</a>  
 </html>

订票
活动ID。
类型
描述
城市
位置
日期
价格
购买


请将复选框置于while循环中,复选框的值具有activityid1。用一个表格把代码围起来。创建Javaservlet或其他jsp

<form method="post" action="<%=request.getContextPath()%>/TestServlet">
 <table 
 <tr>
   ...
while (rs.next()) {

   int activityid1 = rs.getInt("id");
   String type1 = rs.getString("type");
                ...

   out.println("<tr>");
   out.println("<td>" + activityid1 + "</td>");
   out.println("<td>" + type1 + "</td>");
   out.println("<td><b><font color='#663300'><input type='checkbox' name='ticket' value='"+activityid1+"'/></font></td></b>");

   out.println("</tr>");

 }
 </table>
    <td colspan="10"><input type="submit" value="Submit" /></td>
 </form>
最后,将ActivityID与用户\u id一起保存

你可以看看这个

也可以使用JSTL库。不建议在JSP页面中编写更多java代码。连接Java类中的数据库


我希望这会有所帮助。

您所说的复选框位置是什么意思?我无法理解提交部分
String [] val = request.getParameterValues("ticket");