<%@ 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"> <inputtype="button" name="submit1" value="提交" onclick="Mycheck();"></form><form action="" ?formid=2 name="form2" method="post">表單2: <input type="text" name="text2" class="text"> <inputtype="button" name="submit2" value="提交" onclick="Mycheck1();"></form><form action="" ?formid=3 name="form3" method="post">表單3: <input type="text" name="text3" class="text"> <inputtype="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>