简体   繁体   English

如何使用JSP,Spring MVC,Hibernate在弹出窗口中发送参数

[英]how to send parameters in a popup window using JSP, Spring MVC, Hibernate

New to JSP and JavaScript but familiar with Spring MVC and Hibernate. JSP和JavaScript的新手,但熟悉Spring MVC和Hibernate。 I am trying to insert values to database using a popup window after user clicks on the create button. 我试图在用户单击创建按钮后使用弹出窗口将值插入数据库。 Steps: 1. User clicks the create button 2. a popup window opens with the text boxes to input values (like name, age) 3. two buttons with in the popup to save and cancel. 步骤:1.用户单击“创建”按钮2.一个弹出窗口打开,带有文本框以输入值(如名称,年龄)。3.弹出窗口中的两个按钮用于保存和取消。 Once save is clicked then it goes to the controller and save to DB. 单击保存后,它将进入控制器并保存到数据库。 Cancel is to return back to the previous page. 取消是返回上一页。

Am able to do this with out popup window but i want it to work with the popup window. 能够在没有弹出窗口的情况下执行此操作,但我希望它与弹出窗口一起工作。 Thanks. 谢谢。

Code Snippet is Below....It doesnt bring show the popup window when i click the create button. 代码段如下。。。当我单击“创建”按钮时,它不显示弹出窗口。

My Jsp: 我的Jsp:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
        function showPopupWindow() {
            document.getElementById('popupWindow').style.display = 'block';

        }
        </script>
<title>Insert title here</title>
</head>
<body>

<button onclick="showPopupWindow()">create</button>
<button class="sendBtn" onclick="closePopupWindow()">Cancel</button>
<div id="popupWindow">
 <form:form commandName="person" action="createP" method="post" name="myForm" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="name">name</label>
                                <div class="col-xs-4">
                                    <form:input type="text" id ="name" path="name" class="form-control"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="age">age</label>
                                <div class="col-xs-4">
                                    <form:input type="text" id ="age" path="age" class="form-control"/>
                                </div>
                            </div>


                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                    <input type="submit" id ="buttonUpdate"  value="save" class="btn btn-default"/>
                                </div>
                            </div> 



                        </form:form>
</div>
</body>
</html>

Regarding to your code your div is always shownup since your style on the div is not none 关于您的代码,由于div上的样式不为空,因此始终显示div

<div id="popupWindow" style="display:none;">

Why not using jquery instead of default javascript ? 为什么不使用jquery而不是默认javascript? It is already has dialog function which view your div as dialog 它已经具有对话框功能,可将div作为对话框查看

$("#popupWindow").dialog();
//After that you can send your form in an ajax request
$.ajax({
   url:url,
   data:$(form).serialize(),
   success:function(data) {
       //dosomething();
    }
});

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

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