03-同一页面中的多表单提交(jsp基本应用)

时间:2022-11-23 10:50:32
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>同一页面中的多表单提交</title>
<script type="text/javascript">
function Mycheck() {
if (form1.text1.value == "") {
alert("请输入表单内容!");
form1.text1.focus();
return;
}
form1.submit();
}
function Mycheck1() {
if (form2.text2.value == "") {
alert("请输入表单内容!");
form2.text2.focus();
return;
}
form2.submit();
}
function Mycheck2() {
if (form3.text3.value == "") {
alert("请输入表单内容!");
form3.text3.focus();
return;
}
form3.submit();
}
</script>
</head>

<body>
<form action="" ?formid=1 name="form1" method="post">
表单1: <input type="text" name="text1" class="text"> <input
type="button" name="submit1" value="提交" onclick="Mycheck();">
</form>
<form action="" ?formid=2 name="form2" method="post">
表单2: <input type="text" name="text2" class="text"> <input
type="button" name="submit2" value="提交" onclick="Mycheck1();">
</form>
<form action="" ?formid=3 name="form3" method="post">
表单3: <input type="text" name="text3" class="text"> <input
type="button" name="submit3" value="提交" onclick="Mycheck2();">
</form>
<%
String text1 = "";
String text2 = "";
String text3 = "";
String message = "";
if (request.getParameter("text1") != null) {
text1 = request.getParameter("text1");
message = "提交了第一个表单,提交内容为" + text1 + "";
out.print(message);
}
if (request.getParameter("text2") != null) {
text2 = request.getParameter("text2");
message = "提交了第2个表单,提交内容为" + text2 + "";
out.print(message);
}
if (request.getParameter("text3") != null) {
text3 = request.getParameter("text3");
message = "提交了第3个表单,提交内容为" + text3 + "";
out.print(message);
}
%>
</body>
</html>

03-同一页面中的多表单提交(jsp基本应用)