java - 为什么在jsp中检索数据不更新

标签 java jsp oracle11g

我有三个JSP,如下:

  1. Employee_vendor_approve.jsp:检索员工详细信息

  2. update_employeeVendorLoginCredentials.jsp:更新过程引用Employee_vendor_approve.jsp页面

  3. update_process_employeeVendorLoginCredentials.jsp:正在更新检索数据

从第 1 点开始,我可以检索数据,但无法继续第 2 点和第 3 点。我无法找到问题在哪里,当我单击 Employee_vendor_approve.jsp 上的更新链接时,update_employeeVendorLoginCredentials.jsp 显示为空白,这是我的代码

Employee_vendor_approve.jsp:

 <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Employee and vendor approve Page</title>
    </head>
    <body>
        <table border="1" align="center">
            <tr>
                <td>FIRST_NAME </td>
                <td>LAST_NAME</td>
                <td>ORGANIZATION_NAME</td>
                <td>EMPLOYEE_ID</td>
                <td>Approve</td>
                <td>Status</td>
            </tr>
            <%
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con==DriverManager.getConnection("jdbc:oracle:thin:@173.18.114.213:1821:godb","ex","xe");

            statement=con.createStatement();
            String Sql="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where role in ('Employee','Vendor')";
            resultSet=statement.executeQuery(Sql);       

         while(resultSet.next()){
          %>
           <tr>
              <td><%=resultSet.getString("FIRST_NAME")%></td>
              <td><%=resultSet.getString("LAST_NAME")%></td>
              <td><%=resultSet.getString("ORGANISATION_NAME")%></td>
              <td><%=resultSet.getString("EMPLOYEE_ID")%></td>
              <td><%=resultSet.getString("APPROVE")%></td>
              <td>
               <a href="update_employeeVendorLoginCredentials.jsp?id=<%=resultSet.getString("EMPLOYEE_ID")%>">update</a>               
            </td>  
        </tr>   
        <%
    }
      //con.close();
    %>
        </table>
    </body>
</html>

update_employeeVendorLoginCredentials.jsp:

     <html>
        <body>
<form method="post" action="update_process_employeeVendorLoginCredentials.jsp">

    <table border="1">
        <tr>
             <th>FIRST_NAME </th>
                <th>LAST_NAME</th>
                <th>ORGANIZATION_NAME</th>
                <th>EMPLOYEE_ID</th>
                <th>Approve</th>
        </tr>
        <%
        String employee_id=request.getParameter("employee_id");

        int sumcount=0;
        try
        {
               Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@173.18.114.213:1821:godb","ex","xe");

         Statement st=con.createStatement();

          String query="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where EMPLOYEE_ID="+employee_id;

          ResultSet rs=st.executeQuery(query);

          while(rs.next())
          {
              %>
              <tr>
                  <td><input type="text" name="FIRST_NAME" value="<%=rs.getString("FIRST_NAME")%>"> </td>
                  <td><input type="text" name="LAST_NAME" value="<%=rs.getString("LAST_NAME")%>"> </td>
                  <td><input type="text" name="ORGANISATION_NAME" value="<%=rs.getString("ORGANISATION_NAME")%>"> </td>
                  <td><input type="text" name="APPROVE" value="<%=rs.getString("APPROVE")%>"> </td>
                  <td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td>
              </tr>
              <tr>
                  <td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
              </tr>

             <%  }

        }
        catch(Exception ex)
        {

        }

        %>
    </table>    
</form>
        </body>
 </html>

update_process_employeeVendorLoginCredentials.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@173.18.114.213:1821:godb","ex","xe");

        String EMPLOYEE_ID=request.getParameter("EMPLOYEE_ID");
        String first_name=request.getParameter("FIRST_NAME");
        String Last_name=request.getParameter("LAST_NAME");
        String ORGANISATION_NAME=request.getParameter("ORGANISATION_NAME");
        String Approve_status=request.getParameter("APPROVE");

        if (EMPLOYEE_ID!=null) 
        {


        // Connection con = null;
        PreparedStatement ps = null;
        int personID = Integer.parseInt(EMPLOYEE_ID);       
        try

        {
            String Sql="update REGISTRATION_EMPLOYEE set APPROVE='Y' where EMPLOYEE_ID="+EMPLOYEE_ID;
            ps=con.prepareStatement(Sql);
            ps.setString(1, Approve_status);
            int i=ps.executeUpdate();
            if(i>0)
            {
               out.print("Record Updated Successfully");
        }
        else
        {
        out.print("There is a problem in updating Record.");
        }  
        }
        catch(Exception ex)
        {
            ex.printStackTrace();

        }

        }
        %>
    </body>
</html>

enter image description here

enter image description here

最佳答案

Employee_vendor_approve.jsp:中,您设置名为id的参数名称

<a href="update_employeeVendorLoginCredentials.jsp?id=<%=resultSet.getString("EMPLOYEE_ID")%>">update</a> 

但在 update_employeeVendorLoginCredentials.jsp 中,您通过 employee_id 获取参数

String employee_id=request.getParameter("employee_id");

它们不保持相同,所以你得到空值。为了解决这个问题,你可以将其更改为以下内容:

String employee_id=request.getParameter("id");//using id instead of employee_id
<小时/>

对于无法更新数据的问题,也是由于您在 update_employeeVendorLoginCredentials.jsp 中获取了错误的值:

 <td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td> // you have get the wrong value for id

为了让它工作,请将其更改如下:

<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString("EMPLOYEE_ID")%>"></td> 

关于java - 为什么在jsp中检索数据不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49851958/

相关文章:

Java Servlets 转发一个 View ,其中有一个指向 css 的链接

oracle - 可以将 oracle 11g 客户端与 10g 服务器一起使用吗?

java - Java 中泛型的工作

java - 从抽象类继承注释?

html - 编辑那些 1 像素背景图像的最佳方法是什么?

backup - 进行物理备份时是否可以忽略某些表空间

c# - 使用简单数据的连接池的问题

java - 钱能买到的最好的工具

java - ByteBuddy rebase 、合成类型和 OSGi

java - 如何从 JSP 页面生成 PDF 报告?