如何从 JSP 文本框检索数据并在同一页面的 JQuery 警告框中显示数据?
How to retrieve the data from a JSP textbox and display the data in a JQuery alert box in the same page?
我正在 JSP 中创建一个简单的网页,其中我将使用一个文本框和一个按钮。要求是一旦用户在输入一些文本后单击按钮,屏幕必须显示一个显示输入名称的警告。我必须使用 JQuery 插件之一来实现此目的。以下是供您参考的示例代码:
文件名: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 警告框内的文本框 id=myText。
根据您的情况添加脚本。
<% } else {%>
<script>
$.alert({
title: 'Alert!',
content: '<%= myText%>',
});
</script>
<% }%>
我正在 JSP 中创建一个简单的网页,其中我将使用一个文本框和一个按钮。要求是一旦用户在输入一些文本后单击按钮,屏幕必须显示一个显示输入名称的警告。我必须使用 JQuery 插件之一来实现此目的。以下是供您参考的示例代码:
文件名: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 警告框内的文本框 id=myText。
根据您的情况添加脚本。
<% } else {%>
<script>
$.alert({
title: 'Alert!',
content: '<%= myText%>',
});
</script>
<% }%>