代码之家  ›  专栏  ›  技术社区  ›  Md Kamran Azam

如何从JSP文本框中检索数据并在同一页面的JQuery警报框中显示数据?

  •  1
  • Md Kamran Azam  · 技术社区  · 6 年前

    文件名:b.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
             pageEncoding="ISO-8859-1"%>
    <%@page import="java.sql.Connection,java.sql.PreparedStatement,java.sql.DriverManager,java.sql.ResultSet" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <script src="jquery-confirm-master/dist/jquery-confirm.min.js"></script>
            <link  rel="stylesheet" href="jquery-confirm-master/dist/jquery-confirm.min.css">
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <title>JSP Test - b.jsp</title>
        </head>
        <body>
            <form action="b.jsp">
                <table border="1">
                    <tr>
                        <td>Text:</td>
                        <td><input type="text" name="myText" id="myText" value=""></td>
                        <td><input type="Submit" value="Click to Submit"></td>
                    </tr>
                </table>
            </form>
            <br>
            <%
                String myText = request.getParameter("myText");
                if (myText == null) {
                    // myText is null when the page is first requested, 
                    // so do nothing
                } else {
                    if (myText.length() == 0) {
                        // There was a querystring like ?myText=
                        // but no text, so myText is not null, but 
                        // a zero length string instead.
            %>
            <b>myText is empty</b>
            <% } else {%>
            <b>myText is <%= myText%></b>
            <%
                    }
                }
            %>
            <input type="button" id="alert" value="alert me" onclick="bn()">
            <script>
                function bn() {
                    $.alert({
                        title: 'Alert!',
                        content: 'Simple alert!',
                    });
                }
            </script>
        </body>
    </html>
    

    在上面的代码中,我创建了单独的按钮“Alert”来显示警报框(使用jquery插件),但是如果我想在jquery警报框中显示在text box id=myText中输入文本的警报框,该怎么办。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Roshana Pitigala Laxmansinghsodhanohdiyala    6 年前

    在条件中添加脚本。

    <% } else {%>
        <script>
            $.alert({
                title: 'Alert!',
                content: '<%= myText%>',
            });
        </script>
    <% }%>