简体   繁体   中英

When i click edit in html table how to send those details same page text boxes to update in jsp

I have jsp page in that I did insert and displaying records in html table in one page only in when i click edit it redirect to update.jsp page but i need to do same page only without taking another update.jsp page

Is it possible to do Insert,Update,Delete in single page?

yes it is possible to edit in same page.

You can use ajax for it. form of project insert in jsp using jstl

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<c:if test="${empty sessionScope['loginUser']}">
    <c:redirect url="login.jsp" />
</c:if>
<jsp:include page="header.jsp" />

<!-- Content -->
                <!-- Basic inputs -->
                            <!-- Basic inputs -->
 <script src="http://code.jquery.com/jquery-1.10.1.min.js" ></script>
<script>
$(document).ready(function(){
    $("form").on('submit',function(event){
    event.preventDefault();

             var p_title = document.getElementById('p_title').value;                      
             var p_decription = document.getElementById('p_decription').value;
             var s_date = document.getElementById('s_date').value;                        
             var e_date = document.getElementById('e_date').value;
             var p_language = document.getElementById('p_language').value;

        $.ajax({
                    type: "POST",
                    url: "insert_project.jsp",
                    data: {p_title:p_title,p_decription:p_decription,s_date:s_date,e_date:e_date,p_language:p_language},
                }).done(function(data){
                    alert("Data Inserted succesfullly");

                });

    });

});
</script>



            <form action="#">
             <div id="main_wrapper">
                <div class="container-fluid">
                    <fieldset>
                    <legend><span>Add Project Details</span></legend>
                    </fieldset>

                                 <div class="row">
                                  <div class="col-lg-6">
                                   <div class="form-group">
                                   <label class="control-label">Project Title:</label>
                                   <input type="text" name="p_title" id="p_title" class="form-control" />
                                   </div>


                                <div class="form-group">
                                <label class="control-label">Project Description:</label>
                                <input class="form-control" type="text" name="p_decription" id="p_decription" />
                                </div>


                               <div class="form-group">
                                <label class="control-label">Start Date:</label>
                                <input class="form-control" type="text" name="s_date" id="s_date" />
                                </div>

                                <div class="form-group">
                                 <label class="control-label">End Date:</label>
                                 <input class="form-control" type="text" name="e_date" id="e_date" />
                                 </div>

                                  <div class="form-group">
                                   <label class="control-label">Project Language:</label>
                                   <input class="form-control" type="text" name="p_language" id="p_language" /></div>
                                    </div>
                                    </div>

                                 <div class="form-actions">
                                 <button type="submit" class="btn btn-primary">Submit</button>
                                  <button type="reset" class="btn">Reset</button>  
                                   </div>
                </div>
                </div>


                </form>
                <!-- /basic inputs -->

                          <jsp:include page="sidebar.jsp" />

insert_project.jsp

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@include file="connection.jsp"%>



<sql:update dataSource="${snapshot}" var="result">
            INSERT INTO project_master(project_title,project_description,project_start_date,project_end_date,project_language) VALUES (?,?,?,?,?);
            <sql:param value="${param.p_title}" />
            <sql:param value="${param.p_decription}" />
             <sql:param value="${param.s_date}" />
              <sql:param value="${param.e_date}" />
             <sql:param value="${param.p_language}" />
</sql:update>

this is how you can use ajax in jsp. this is demo of insert you can pass is for update and delete in ajax and make page for it write code for update and delete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM