如何使用JSP,Spring MVC,Hibernate在弹出窗口中发送参数 [英] how to send parameters in a popup window using JSP, Spring MVC, Hibernate

查看:57
本文介绍了如何使用JSP,Spring MVC,Hibernate在弹出窗口中发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSP和JavaScript的新手,但熟悉Spring MVC和Hibernate.我试图在用户单击创建按钮后使用弹出窗口将值插入数据库.脚步:1.用户单击创建按钮2.打开一个带有文本框的弹出窗口,以输入值(例如姓名,年龄)3.弹出窗口中的两个按钮用于保存和取消.单击保存后,它将转到控制器并保存到数据库.取消是返回上一页.

New to JSP and JavaScript but familiar with Spring MVC and 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. 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.

我的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>

推荐答案

关于您的代码,始终显示div,因为您在div上的样式不是

Regarding to your code your div is always shownup since your style on the div is not none

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

为什么不使用jquery而不是默认javascript?它已经具有对话框功能,可将您的div查看为对话框

Why not using jquery instead of default javascript ? It is already has dialog function which view your div as dialog

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

这篇关于如何使用JSP,Spring MVC,Hibernate在弹出窗口中发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆