index.jsp
<script language="javascript">
function Mycheck(){
if(form1.text1.value==""){
alert("Please input something!");form1.text1.focus();return;
}
form1.submit();
}
</script>
<script language="javascript">
function Mycheck1(){
if(form2.text2.value==""){
alert("Please input something!");form2.text2.focus();return;
}
form2.submit();
}
</script>
<script language="javascript">
function Mycheck2(){
if(form3.text3.value==""){
alert("Please input something!");form3.text3.focus();return;
}
form3.submit();
}
</script>
<%
String text1="";
String text2="";
String text3="";
String message="";
if(request.getParameter("text1")!=null){
text1=request.getParameter("text1");
message="You submited the first form,content is "+text1+".";
}
if(request.getParameter("text2")!=null){
text2=request.getParameter("text2");
message="You submited the second form,content is "+text2+".";
}
if(request.getParameter("text3")!=null){
text3=request.getParameter("text3");
message="You submited the third form,content is "+text3+".";
}
%>
<form name="form1" method="post" action="?formid=1">
Form 1:
<input name="text1" type="text" class="text" value="<%=text1 %>">
<input type="button" name="submit1" value="Submit" onclick="Mycheck();">
</form>
<form name="form2" method="post" action="?formid=2">
Form 2:
<input name="text2" type="text" class="text" value="<%=text2 %>">
<input type="button" name="submit2" value="Submit" onclick="Mycheck1();">
</form>
<form name="form3" method="post" action="?formid=3">
Form 3:
<input name="text3" type="text" class="text" value="<%=text3 %>">
<input type="button" name="submit3" value="Submit" onclick="Mycheck2();">
</form>
<%=message %>
网友评论