-1

如何使提交 TRUE 结果我的意思是从 2 INPUT 字段如何仅将一个值字段发布到同一个 JSP 页面,例如

<% string param=req.......

最重要的是我的 jdbc PreparedStatement 必须写两次,因为两个字段...用于检查 EMPLOYEE NO || 的 Oracle DB 姓名

通过使用名称字段,它工作正常,在使用数字更改代码后,它工作正常,但我希望你帮助我有什么好的方法来编码这些东西

这是 HTML 表单

 <form id="contact" method="get">
             <b>Employee No: </b> <input type="text" id="contact_number" size="15" name="number"/>
         &nbsp; &nbsp;
        <b>Employee Name:</b> <input type="text" id="contact_name" size="25" name="name"/>  
                 &nbsp; &nbsp;
    <input type="submit"/>
        </form>

这是验证 jQuery

$(document).ready(function() {
    $("#contact").submit(function() {
        if (($('#contact_number').val().length !== 0) && ($('#contact_name').val().length !== 0)) {
            return false;
        } else if (($('#contact_number').val().length === 0) && ($('#contact_name').val().length === 0)) {
            return false;
        } else {
            return true;
        }
    });
});

这是完整的 JSP & String sql="Oracle query" & JDBC

<%String number = request.getParameter("number");
String name = request.getParameter("name");
if (name != null) { %>
    <h3 id="myDiv"> Search results for  <i> <%= name %> </i> </h3>
<% }
else { %>
    <h4> Enter any Information on above field ... </h4>
<% } %>
<br>
<%@page import="java.sql.*" %>
<%Class.forName("oracle.jdbc.driver.OracleDriver");
String sql="SELECT * FROM RWEMP WHERE ENAME= ?";
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hari","root");
PreparedStatement stat=con.prepareStatement(sql);
stat.setString(1,name);
ResultSet rs=stat.executeQuery();
try {
    if(rs!=null) {
        %>
        <table class="gridtable" border=1 cellspan=60 cellpadding=16>
        <tr>
        <th> Emp ID </th>
        <th> Emp Name </th>
        <th> Emp Dept </th>
        <th> Emp D.o.B </th>
        <th> Show Record </th>
        <th> Record Update </th>
        <th> Compassionate </th>
        </tr>
        <%
        while(rs.next()) {
            %>
            <tr>
            <td><%= rs.getString("EID")%> </td>
            <td><%= rs.getString("ENAME") %> </td>
            <td><%= rs.getString("EDEPT")%> </td>
            <td><%= rs.getString("EDOB")%> </td>
            <td><input class="ui-button" type="button" onSubmit="result.jsp" target="destination" value="Show"></td>
            <td><input class="ui-button" type="button" onclick="update.jsp" target="destination" value="update"></td>
            <td><input class="ui-button" type="button" onclick="compassionate.jsp" target="destination" value="Compassionate"></td>
            </tr>
            <%
        }
    }
}
catch(SQLException e) {
    e.printStackTrace();
}
con.close();
%>
</table>

更多查看仅查看此Fiddle 的HTML 输出

4

1 回答 1

1

我怎样才能使提交 TRUE 结果...我的意思是从 2 INPUT 字段...如何仅将一个值字段发布到同一个 JSP 页面...例如:- <% string param=req.......

为此,请放置一个下拉菜单,说明在您的情况下选择搜索条件是数字和姓名,然后为他提供一个输入字段,因此当您提交表单时,您同时拥有列名和数据到下一页,并且您没有编写 2 个查询.Form 应该是这样的

如果可能,请帮助我,如果用户单击特定用户表行...如何将该用户行详细信息发送到其他 jsp 页面...以完成记录查看或记录编辑目的

解决方案:将该行的 id 传递到其他页面

在每行名称上创建一列,说 Detail 并执行

<a href="/detailed.jsp?user_id="<%=user_id%>>Detail</a>

在 detail.jsp 从 get 参数中获取 user_id 的值,并使用 user_id 应用查询以获取该行的所有详细信息

于 2015-02-01T12:02:03.060 回答