小组成员:陈鹏 李国帅
思路: 使用jsp实现java代码与网页的连接,利用数组实现数据的传输。
源代码:
Ys.jsp
<html> <head> <%@page contentType="text/html;charset=utf-8" import="java.util.*"%> <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> <title>Insert title here</title> </head> <body> <form name="form1" method="post" action="02.jsp"> <center> <p> 请选择您的要求 </p> <p> 有乘除 <input type=checkbox name=cc1 value= true > 有负数 <input type=checkbox name=fu1 value= true > 多个数运算<input type=checkbox name=sys1 value= ture > </p> <p> 最 小值: <input name="min1" type="text" class="input" size="30" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode <48 || event.keyCode>57)) event.returnValue=false"> 最大值: <input name="max1" type="text" class="input" size="30" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode <48 || event.keyCode>57)) event.returnValue=false"> </p> <p> 题数: <input name="number" type="text" class="input" size="30" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode <48 || event.keyCode>57)) event.returnValue=false"></p> <p> <input type="Submit" value="提交"> <input type="Reset" value="重置"> </p> </center> </form> </body> </html>
02.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String cc1 = request.getParameter("cc1"); String kh1 = request.getParameter("kh1"); String fs1 = request.getParameter("fs1"); String yv1 = request.getParameter("yv1"); String fu1 = request.getParameter("fu1"); String sys1 = request.getParameter("sys1"); String min1 = request.getParameter("min1"); String max1 = request.getParameter("max1"); String number = request.getParameter("number"); out.println(cc1+ kh1+yv1+ fs1+ sys1+ min1+ max1+number); boolean cc=false; boolean kh=false; boolean fs=false; boolean yv=false; boolean fu=false; boolean sys=false; if (cc1=="true") { cc=true;}; if (kh1=="true") { kh=true;}; if (fs1=="true") { fs=true;}; if (sys1=="true") { sys=true;}; if (yv1=="true") { yv=true;}; if (fu1=="true") { fu=true;}; int min = Integer.parseInt(min1); int max = Integer.parseInt(max1); int num = Integer.parseInt(number); %> <script type="text/javascript"> function rannum(max2,min2) { int ran =(int)(Math.random()*max2 + min2) return ran; } function exchange(num1,num2, select) { int n; if(select==1)//第一个大 { if(num1<num2) { n=num1; num1=num2; num2=n; } } else { if(num1>num2) { n=num1; num1=num2; num2=n; } } } function ope(max2) { char o; if(rannum(max2,1)==1){o='+';} if(rannum(max2,1)==2){o='-';} if(rannum(max2,1)==3){o='*';} if(rannum(max2,1)==4){o='/';} else{o='!';} } function operation1(max2)//一个运算符没有分数 { var opera[]; int num1,num2,result=0; char ope1=ope(max2); num1=rannum(max,min); num2=rannum(max,min); if(ope1=='+'){result=num1+num2;} if(ope1=='-'){exchange(num1,num2,1);result=num1-num2;} if(ope1=='*'){result=num1*num2;} opera[0]=num1; opera[1]=ope1; opera[2]=num2; opera[3]=result; if(ope1=='/'){exchange(num1,num2,2);opera[3]=num1+'/'+num2;} return opera; } function opration2(max2) { var opera[]; int num1,num2,num3,result; char ope1,ope3; ope1=ope(max2); ope3=ope(max2); num1=rannum(max,min); num2=rannum(max,min); num3=rannum(max,min); if(ope1=='+'){result=num1+num2;} if(ope1=='-'){exchange(num1,num2,1);result=num1-num2;} if(ope1=='*'){result=num1*num2;} if(ope1=='/'){exchange(num1,num2,2);result=num1/num2;} opera[0]=num1; opera[1]=ope1; opera[2]=num2; opera[3]=result; return opera; } </script> <script type="text/javascript"> var sz=[]; var ds=[]; var input=[]; if(sys==true)//有多位运算符 { if(cc==true)//有乘除 { } else{}//没有乘除 } else//以为运算符 { if(cc==true)//有乘除 { } else { }//没有乘除 } </script> </body> </html>
截图:
总结:这个作业做得不好,没有在特定的时间内做出来,今后要好好学习。