简体   繁体   English

当我单击html表中的“编辑”时,如何发送这些详细信息同一页文本框以在jsp中进行更新

[英]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 我有jsp页面中,我没有插入,只有在当我点击编辑重定向到一个页面显示在HTML表中的记录update.jsp页面,但我只需要而无需再次做同样的页面update.jsp

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. 您可以使用ajax。 form of project insert in jsp using jstl 使用jstl在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"%>
<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 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. 这就是在jsp中使用ajax的方法。 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. 这是插入的演示,您可以通过它在ajax中进行更新和删除,并为其创建页面编写更新和删除代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击按钮时如何更新html / jsp页面的特定部分? - How to update a specific section of html/jsp page on click of button? 当我单击同一页面上的元素时,如何加载不同的文本? - How to load a different text when i click on element at the same page? 使用 Jquery 编辑 HTML 表格(使用按钮添加文本框) - Edit the HTML table using Jquery( adding text boxes using buttons) 如何在单击按钮时对HTML页面进行编程以更新从文本文件导入的文本? - How do I program an HTML page to update text imported from a text file on button click? 如何通过单击按钮并动态增加行数来向html表添加两个文本框文本? - How to add two text boxes texts to html table with button click and increment rows dynamically? 如何将响应文本显示为html并同时发送到php页面 - how to display response text as html and at the same time send to a php page 单击时编辑 HTML 文本 - Edit HTML text on click 当用户单击一行时将数据发送到新的jsp页面 - send data to a new jsp page when user click on a row 如何遍历页面源中的所有文本框元素并查找所有这些文本框的名称? - How to loop through all text box elements in a page source and find the names of all those text boxes? 如何将使用javascript动态创建的HTML表发送到另一个页面(servlet,jsp等)? - How to send an HTML table,which is created dynamically using javascript,to a another page(servlet,jsp etc)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM