在HTML中将按钮添加到按钮

时间:2017-06-06 07:44:57

标签: javascript jsp

<html>
<%@ page import="java.sql.*" %>
<head>
<title>Sarvotam List</title>
<link rel="stylesheet" href="Styles/main.css">
</head>
<body>
<div class="seg">
    <form action="main.jsp" method="post">
    <table class="data" align="center" width=80%>
        <tr>
            <th width=20%>Qualification Exam</th>       
            <th width=20%>Course Type</th>
            <th width=20%>Duration</th>
            <th width=20%>Number of Cheques</th>
            <th width=20%>Course_Category</th>
        </tr>
        <tr>
            <td width=20% align="center"><input type="text" name="qual" 
  width=20%></td>
            <td width=20% align="center"><input type="text" name="ctype" 
  width=20%></td>
            <td width=20% align="center"><input type="number" name="dur" 
  width=20%></td>
            <td width=20% align="center"><input type="number" name="che" 
width=20%></td>
            <td width=20% align="center"><select name="opt">
                    <option id="ENG">ENG</option>
                    <option id="MED">MED</option>
                    <option id="OTH">OTH</option>
                    <option id="PG">PG</option>
                </select>
        </tr>
        <tr>
            <td width=20% align="center"><input type="text" name="qual" 
 width=20%></td>
            <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td>
            <td width=20% align="center"><input type="number" name="dur" 
     width=20%></td>
            <td width=20% align="center"><input type="number" name="che" 
width=20%></td>
            <td width=20% align="center"><select name="opt">
                    <option id="ENG">ENG</option>
                    <option id="MED">MED</option>
                    <option id="OTH">OTH</option>
                    <option id="PG">PG</option>
                </select>
        </tr>
        <tr>
            <td width=20% align="center"><input type="text" name="qual" 
width=20%></td>
            <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td>
            <td width=20% align="center"><input type="number" name="dur" 
width=20%></td>
            <td width=20% align="center"><input type="number" name="che" 
width=20%></td>
            <td width=20% align="center"><select name="opt">
                    <option id="ENG">ENG</option>
                    <option id="MED">MED</option>
                    <option id="OTH">OTH</option>
                    <option id="PG">PG</option>
                </select>
        </tr>
        <tr>
            <td width=20% align="center"><input type="text" name="qual" 
width=20%></td>
            <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td>
            <td width=20% align="center"><input type="number" name="dur" 
width=20%></td>
            <td width=20% align="center"><input type="number" name="che" 
width=20%></td>
            <td width=20% align="center"><select name="opt">
                    <option id="ENG">ENG</option>
                    <option id="MED">MED</option>
                    <option id="OTH">OTH</option>
                    <option id="PG">PG</option>
                </select>
        </tr>
        <tr>
            <td width=20% align="center"><input type="text" name="qual" 
  width=20%></td>
            <td width=20% align="center"><input type="text" name="ctype" 
 width=20%></td>
            <td width=20% align="center"><input type="number" name="dur" 
    width=20%></td>
            <td width=20% align="center"><input type="number" name="che" 
width=20%></td>
            <td width=20% align="center"><select name="opt">
                    <option id="ENG">ENG</option>
                    <option id="MED">MED</option>
                    <option id="OTH">OTH</option>
                    <option id="PG">PG</option>
                </select>
        </tr>
            </table>
        <center><button id="submit" name="save">Submit</button></center>

<%              try{
    ResultSet rs=null;
    Statement st=null;
    Connection conn = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = 
   DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", 
   "system", "parents94");
            st=conn.createStatement();
            int i=0;
            String s = request.getParameter("save");
            String[] qual=request.getParameterValues("qual");
            String[] ctype=request.getParameterValues("ctype");
            String[] dur=request.getParameterValues("dur");
            String[] noc=request.getParameterValues("che");
            String[] cou=request.getParamterValues("opt");
            if(s!=null)
            while(qual[i].length()!=0){
                st.executeUpdate("insert into SCHOL_COURSE_MASTER values('"+qual[i]+"','"+ctype[i]+"','"+dur[i]+"','"+noc[i]+"','"+cou[i]+"')");
                i++;
            }
        conn.close();
        st.close(); 
            }
catch(Exception e)
    {
        e.getMessage();
    }
%>
</form> 
</div>
  </body>
 </html>

这是我的代码 我需要从表中的用户那里获取输入并添加到数据库中 所有连接都有效 但是sql查询不会导致数据库中的任何更改 我只需要帮助知道如何编写代码来按下提交按钮

2 个答案:

答案 0 :(得分:3)

将提交类型添加到按钮:

<center>
    <button type="submit" id="submit" name="save">Submit</button>
</center>

答案 1 :(得分:0)

首先你可能想检查一下 点击事件已被触发?

然后尝试打印,如果你得到正确的值或它是否为空

如果您在帖子中包含错误,则错误会更好