пытается редактировать загруженные данные формы, используя jsp - PullRequest
0 голосов
/ 31 января 2020

Я написал программу для загрузки файлов с помощью JSP и загрузки файлов в базу данных MySQL. Существует один список файлов. jsp страница, она включает в себя все файлы, загруженные пользователем, и на этой странице все данные будут получены из базы данных, и это успешно. Теперь я добавил один дополнительный столбец (" Редактировать файл ") в список файлов. jsp страница. Когда пользователь нажимает кнопку «Изменить», должна отображаться форма с предыдущими данными, и пользователь будет вносить изменения в соответствии с потребностями и нажимать кнопку «Обновить». Но я получаю разные результаты. Я также приложил редактировать. jsp страницу.

Это мое редактирование. jsp страница

   
<%@page import="java.io.File"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>edit Page</title>
        <style>
            tr,td,th{
                padding: 20px;
                text-align: center;
            }
        </style>
    </head>
    
    <body>
        <br>
        <%
            Connection con = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            
            
            %>
            
            <table border="2">
            <tr>
                <th style="width: 20%">Z ID</th>
                <th style="width: 20%">First Name</th>
                <th style="width: 20%">Last Name</th>
                <th style="width: 20%">Mail ID</th>
                <th style="width: 20%">Division</th>
                <th style="width: 20%">Department</th>
                <th style="width: 20%">Cost Center Code</th>
                <th style="width: 20%">Document No.</th>
                <th style="width: 20%">Document Name</th>
                
               
                <th style="width: 20%">Document Type</th>
                <th style="width: 20%">Document Category</th>
                <th style="width: 20%">Document Classification</th>
                <th style="width: 20%">Authorised By</th>
                <th style="width: 20%">Validity - From Date</th>
                <th style="width: 20%">Validity - To Date</th>
                <th style="width: 20%">Document Level</th>
                <th style="width: 20%">Document General(F31151)</th>
                <th style="width: 20%">Serial No.</th>
                
                <th style="width: 20%">Revision No.</th>
                <th style="width: 20%">Issuer</th>
                <th style="width: 20%">Status</th>
                <th style="width: 20%">File Name</th>
                <th style="width: 20%">File Path</th>
                <th style="width: 20%">Added Date</th>
                <th style="width: 20%">Download</th>
            </tr>
            <%
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dmsqms","root","");
                
                
                
                Statement stat = null;
                stat = con.createStatement();
                String u = request.getParameter("zid");
                
                String data = "select * from dmsfiles where zid = '"+u+"'";
                rs = stat.executeQuery(data);
                
                while(rs.next()){
                    
                
                
            %>
        
            
            <tr>
                <td><%=rs.getString(1)%></td>              
                <td><%=rs.getString(2)%></td>           
                <td><%=rs.getString(3)%></td>   
                <td><%=rs.getString(4)%></td> 
                <td><%=rs.getString(5)%></td> 
                <td><%=rs.getString(6)%></td> 
                <td><%=rs.getString(7)%></td>
                <td><%=rs.getString(8)%></td>              
                <td><%=rs.getString(9)%></td>
                <td><%=rs.getString(10)%></td>          
                <td><%=rs.getString(11)%></td> 
                <td><%=rs.getString(12)%></td>           
                <td><%=rs.getString(13)%></td>
                <td><%=rs.getString(14)%></td>
                <td><%=rs.getString(15)%></td>
                <td><%=rs.getString(16)%></td>
                <td><%=rs.getString(17)%></td>
                <td><%=rs.getString(18)%></td>
                <td><%=rs.getString(19)%></td>
                <td><%=rs.getString(20)%></td>
                <td><%=rs.getString(21)%></td>
                <td><%=rs.getString(22)%></td>
                <td><%=rs.getString(23)%></td>
                <td><%=rs.getString(24)%></td>
                      
                <td><a href="DownloadServletClass?fileName=<%=rs.getString(22)%>">Download</a></td>
                  
            </tr>
            <%
                }
            %>    
        </table><br>
        <button type="submit" class="btn btn-warning">Update</button>
        <a href="index.jsp" class="btn btn-default">Back</a>
        
    </body>
</html>
<%
            String z_id = request.getParameter("zid");
            String first_Name = request.getParameter("firstname");
            String last_Name = request.getParameter("lastname");
            String mail_i_d = request.getParameter("mailid");
            String d_iv = request.getParameter("division");
            String de_pt = request.getParameter("department");
            String cost_centercode = request.getParameter("costcentercode");
            String doc_num = request.getParameter("documentnumber");                 //textbox value of documentnumber field
            String doc_Name = request.getParameter("documentname");
            String doc_Type = request.getParameter("Document_Type");                 //textbox value of Document_Type field
            String doc_Category = request.getParameter("Document_Category");   
            String doc_classification = request.getParameter("Document_Classification");
            String authorised_by = request.getParameter("authorisedby");
            String from_date = request.getParameter("fromdate");
            String to_date = request.getParameter("todate");
            
            String document_level = request.getParameter("documentlevel");
            String document_general = request.getParameter("documentgeneral");
            String serial_number = request.getParameter("serialnumber");
            String revision_number = request.getParameter("revisionnumber");
            String iss_uer = request.getParameter("issuer");
            String sta_tus = request.getParameter("status");
            String file_Name = "";
            String folder_Name = "allfiles";
            String pa_th = folder_Name + File.separator + file_Name;
            Timestamp add_ed_date = new Timestamp(System.currentTimeMillis());
            
            if(z_id != null && first_Name != null && last_Name != null && mail_i_d != null && d_iv != null && de_pt != null && cost_centercode != null && doc_num != null && doc_Name != null && doc_Type != null && doc_Category != null && doc_classification != null && authorised_by != null && from_date != null && to_date != null && document_level != null && document_general != null && serial_number != null && revision_number != null && iss_uer != null && sta_tus != null && file_Name != null && folder_Name != null && pa_th != null && add_ed_date != null){
                String query = "update dmsfiles set zid=?,firstname=?,lastname=?,mailid=?,division=?,department=?,costcentercode=?,document_number=?,document_name=?,document_type=?,document_category=?,document_classification=?,authorised_by=?,fromdate=?,todate=?,document_level=?,document_general=?,serial_number=?,revision_number=?,issuer=?,status=?,filename=?,path=?,added_date=? where zid='"+z_id+"'";
                ps = con.prepareStatement(query);
                
                ps.setString(1,z_id);
                ps.setString(2,first_Name);
                ps.setString(3,last_Name);
                ps.setString(4,mail_i_d);
                ps.setString(5,d_iv);
                ps.setString(6,de_pt);
                ps.setString(7,cost_centercode);
                ps.setString(8,doc_num);
                ps.setString(9,doc_Name);
                ps.setString(10,doc_Type);
                ps.setString(11,doc_Category);
                ps.setString(12,doc_classification);
                ps.setString(13,authorised_by);
                ps.setString(14,from_date);
                ps.setString(15,to_date);
                ps.setString(16,document_level);
                ps.setString(17,document_general);
                ps.setString(18,serial_number);
                ps.setString(19,revision_number);
                ps.setString(20,iss_uer);
                ps.setString(21,sta_tus);
                ps.setString(22,file_Name);
                
                ps.setString(23,pa_th);
                ps.setTimestamp(24, null);
                ps.executeUpdate();
                response.sendRedirect("filelist.jsp");
                
                
                
                
                
            }
    
    

%>

Я внес следующие изменения в свой список файлов. jsp Страница

<th>Edit File</th>

<td><a href='edit.jsp?zid=<%=rs.getString(1)%>' class="btn btn-warning">Edit</a></td>

Это выводится, когда я нажимаю на опцию редактирования для любой строки.

This is the output when I click on edit option for any row

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...