【问题标题】:how to send parameters in a popup window using JSP, Spring MVC, Hibernate如何使用 JSP、Spring MVC、Hibernate 在弹出窗口中发送参数
【发布时间】:2018-01-19 08:32:51
【问题描述】:

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

我能够在没有弹出窗口的情况下执行此操作,但我希望它与弹出窗口一起使用。谢谢。

代码片段在下面......当我点击创建按钮时它不会显示弹出窗口。

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

【问题讨论】:

  • 浏览器控制台有什么错误吗?
  • 一个选项是使用 bootstrap 作为您的 css 框架,请转到此链接查看模态窗口和其他 ui 控件的一些示例:getbootstrap.com/javascript/#modals

标签: javascript java spring hibernate jsp


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2011-06-15
    相关资源
    最近更新 更多