软件工程结对作业01
程序设计思路:先设计一个页面让用户进行选择自己所需要进行的服务类型,在根据选择的不同的选项跳转到不同的页面再次进行进一步的具体选择。然后根据用户的选项去生成不同的算式存到数据库中,在输出出到web页面上,用户输入得到的结果后在将数字和数据库中的结果进行比对,如果错误就保存错误的题号在最后将错误的题号。
程序源代码:
start。jsp
1 <%@ page contentType = "text/html; charset=utf-8" import = "java.sql.*" errorPage = "error.jsp" %> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>选择</title> 6 <style type="text/css"> 7 body,td,th { 8 font-size: 24px; 9 } 10 body { 11 background-color: #0CF; 12 background-image: url(背景图片.bmp); 13 } 14 </style> 15 </head> 16 <body> 17 <form id="myForm" name="myForm" > 18 <p> </p> 19 <p> </p> 20 <p align="center"> </p> 21 <p align="center"> </p> 22 <p align="center"> </p> 23 <p align="center">请选择需要练习的题目类型</p> 24 <p> </p> 25 <p> 26 <label> 27 <div align="center"> 28 <div align="center"> 29 <input type="radio" name="RadioGroup1" value="zhengshu.jsp" id="RadioGroup1_0" /> 30 整数算数题练习</div> 31 </div> 32 </label> 33 <div align="center"><br /> 34 </div> 35 <label> 36 <div align="center"> 37 <input type="radio" name="RadioGroup1" value="zhenfenshu.jsp" id="RadioGroup1_1" /> 38 真分数算数题练习</div> 39 </label> 40 <div align="center"><br /> 41 </div> 42 <label> 43 <div align="center"> 44 <input type="radio" name="RadioGroup1" value="daikuohao.jsp" id="RadioGroup1_2" /> 45 带括号算数题练习</div> 46 </label> 47 <div align="center"><br /> 48 </div> 49 </p> 50 <p align="center"> 51 <br /> 52 </p> 53 <div align="center"> 54 <input type="button" value="开始答题" onClick="check()" /> 55 </div> 56 </form> 57 <script> 58 function check(){ 59 var input = document.getElementsByName("RadioGroup1"); 60 for(var i=0; i< input.length; i++ ){ 61 if(input[i].checked == true ){ 62 //window.open(input[i].value,null); //新窗口打开 63 window.location=input[i].value; //当前窗口打开,注释一种方法 64 } 65 } 66 } 67 </script> 68 </body> 69 </html>
zhengshu.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.sql.Connection,java.sql.DriverManager"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>整数</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <form id="form1" name="form1" method="post" action="chuanzhi.jsp"> 20 <p> 21 <label for="textfield"></label> 22 </p> 23 <p> </p> 24 <p> </p> 25 <p> </p> 26 <p> </p> 27 <p> </p> 28 <p> </p> 29 <p align="center"><br> 30 最小值:<input type="text" name="min" id="min" /> 31 <br> 32 33 最大值:<input type="text" name="max" id="max" /> 34 <br> 35 题目个数:<input type="text" name="geshu" id="geshu" /> 36 <br> 37 选项:1有乘除法且除法无余数 2有乘除法余数不定 3无乘除法 38 <br> 39 选项: <input type="text" name="choose" id="choose" /> 40 </p> 41 <div align="center"> 42 <input type="submit" value="确定" value="chuanzhi.jsp"> 43 </div> 44 </form> 45 </body> 46 </html>
zhengshushizi.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>整数式子</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <div align="center"> 20 <%! 21 int i=0; 22 String Array[]=new String[1000]; 23 class Zhengshu 24 { 25 String re1=""; 26 int re; 27 String function(int r ,int q, int fun) 28 { 29 //1有乘除法 2加减无负数 3除法无余数(12,1,0) 30 String fu =""; 31 String shizi=""; 32 int a=(int)(Math.random()*(r)%(r-q+1)+q); 33 int b=(int)(Math.random()*(r)%(r-q+1)+q); 34 int c=(int)(Math.random()*4); 35 36 //1有乘除法 37 if(fun==1) 38 { 39 if(c==0) 40 { 41 fu="+"; 42 shizi=a+" "+fu+" "+b; 43 re=a+b; 44 re1=String.valueOf(re); 45 } 46 if(c==1) 47 { 48 fu="-"; 49 //排除负数可能性 50 while(a-b<0) 51 { 52 a=(int)(Math.random()*(r)%(r-q+1)+q); 53 b=(int)(Math.random()*(r)%(r-q+1)+q); 54 } 55 shizi=a+" "+fu+" "+b; 56 re=a-b; 57 re1=String.valueOf(re); 58 } 59 if(c==2) 60 { 61 fu="×"; 62 shizi=a+" "+fu+" "+b; 63 re=a*b; 64 re1=String.valueOf(re); 65 } 66 if(c==3) 67 { 68 fu="÷"; 69 //排除分母为0的可能性和余数的可能性 70 while(b==0||a%b!=0) 71 { 72 a=(int)(Math.random()*(r)%(r-q+1)+q); 73 b=(int)(Math.random()*(r)%(r-q+1)+q); 74 } 75 re=a/b; 76 shizi=a+" "+fu+" "+b; 77 re1=String.valueOf(re); 78 } 79 } 80 81 82 //2有乘除法余数不定 83 if(fun==2) 84 { 85 if(c==0) 86 { 87 fu="+"; 88 re=a+b; 89 re1=String.valueOf(re); 90 shizi=a+" "+fu+" "+b; 91 } 92 if(c==1) 93 { 94 fu="-"; 95 //排除负数可能性 96 while(a-b<0) 97 { 98 a=(int)(Math.random()*(r)%(r-q+1)+q); 99 b=(int)(Math.random()*(r)%(r-q+1)+q); 100 } 101 shizi=a+" "+fu+" "+b; 102 re=a-b; 103 re1=String.valueOf(re); 104 } 105 if(c==2) 106 { 107 fu="×"; 108 re=a*b; 109 re1=String.valueOf(re); 110 shizi=a+" "+fu+" "+b; 111 } 112 if(c==3) 113 { 114 fu="÷"; 115 //排除分母为0的可能性 116 while(b==0) 117 { 118 b=(int)(Math.random()*(r)%(r-q+1)+q); 119 } 120 re=a/b; 121 if(a%b!=0) 122 { 123 int flag1=a%b; 124 re1=String.valueOf(re)+"..."+String.valueOf(flag1); 125 } 126 else 127 re1=String.valueOf(re); 128 shizi=a+" "+fu+" "+b; 129 } 130 } 131 132 //3无乘除法 133 if(fun==3) 134 { 135 if(c==0) 136 { 137 fu="+"; 138 re=a+b; 139 re1=String.valueOf(re); 140 shizi=a+" "+fu+" "+b; 141 } 142 if(c==1) 143 { 144 fu="-"; 145 //排除负数可能性 146 while(a-b<0) 147 { 148 a=(int)(Math.random()*(r)%(r-q+1)+q); 149 b=(int)(Math.random()*(r)%(r-q+1)+q); 150 } 151 re=a-b; 152 re1=String.valueOf(re); 153 shizi=a+" "+fu+" "+b; 154 } 155 if(c==2) 156 { 157 fu="+"; 158 re=a+b; 159 re1=String.valueOf(re); 160 shizi=a+" "+fu+" "+b; 161 } 162 if(c==3) 163 { 164 fu="-"; 165 //排除负数可能性 166 while(a-b<0) 167 { 168 a=(int)(Math.random()*(r)%(r-q+1)+q); 169 b=(int)(Math.random()*(r)%(r-q+1)+q); 170 } 171 re=a-b; 172 re1=String.valueOf(re); 173 shizi=a+" "+fu+" "+b; 174 } 175 } 176 return shizi; 177 } 178 } 179 %> 180 <% 181 182 //加载JDBC驱动 183 String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; 184 //连接服务器和数据库sample 185 String dbpath = "jdbc:sqlserver://localhost:1433; DatabaseName=test"; 186 String username = "sa"; //默认用户名 187 String password = "19961114.wfb"; //密码 188 189 Connection con = null; //定义一个SQL server链接对象 190 Class.forName(driverName).newInstance(); //SQL server驱动 191 con = DriverManager.getConnection(dbpath, username, password); //链接本地SQL server 192 java.sql.Statement stmt; //创建声明 193 stmt = con.createStatement(); 194 int max=Integer.parseInt(String.valueOf(session.getAttribute("max"))); 195 int min=Integer.parseInt(String.valueOf(session.getAttribute("min"))); 196 int choose=Integer.parseInt(String.valueOf(session.getAttribute("choose"))); 197 int geshu=Integer.parseInt(String.valueOf(session.getAttribute("geshu"))); 198 session.setAttribute("geshu1", geshu); 199 //String daan=request.getParameter("daan"); 200 201 int zhengque1=0,cuowu1=0; 202 int zhengque4[]=new int[geshu+10]; 203 int cuowu4[]=new int[geshu+10]; 204 Zhengshu a = new Zhengshu(); 205 //for(int i=0;i<geshu;i++) 206 %> 207 208 209 <% 210 if(i<geshu) 211 { 212 Array[i]=a.function(max,min,choose); 213 if(i>0) 214 { 215 for(int z=0;z<i;z++) 216 { 217 if((Array[z].equals(Array[i]))) 218 { 219 Array[i]=a.function(max,min,choose); 220 z=-1; 221 } 222 } 223 } 224 out.println(i+1+": "+Array[i]+" = "); 225 226 %> 227 <% //将题目和答案写入数据库表 228 String sql="INSERT INTO 四则运算题目2 (shizi,result) VALUES ('"+Array[i]+" = "+"','"+a.re1+"')"; 229 230 //out.println("<script language = 'javaScript'> alert('"+shi+"');</script>"); 231 stmt.executeUpdate(sql); 232 233 %> 234 <br> 235 236 </div> 237 <form id="form1" name="form1" method="post" action="zhengshusjk.jsp"> 238 <p> </p> 239 <p align="center">答案: 240 <input type="text" name="daan" id="daan" /> 241 <% 242 String shi3=Array[i]+" = "; 243 session.setAttribute("shi",shi3); 244 String rere3=a.re1; 245 session.setAttribute("rere",rere3); 246 //String daan3=request.getParameter("daan"); 247 //session.setAttribute("daan",daan3); 248 session.setAttribute("i2",i); 249 250 i++; 251 stmt.close(); 252 con.close(); 253 %> 254 <input type="submit" value="下一个" > 255 </p> 256 </form> 257 258 <div align="center"> 259 <% 260 //String daan3=request.getParameter("daan"); 261 262 //daan3=request.getParameter("daan"); 263 //session.setAttribute("daan",daan3); 264 265 %> 266 267 <% 268 } 269 else 270 { 271 i=0; 272 %> 273 </div> 274 <form action="chakan.jsp" method="post" > 275 <div align="center"> 276 <% 277 String correct=String.valueOf(session.getAttribute("correct1")); 278 String wrong=String.valueOf(session.getAttribute("wrong1")); 279 %> 280 <input type="submit" value="查看成绩" name="button" align="middle"> 281 </div> 282 </form> 283 <div align="center"> 284 <% 285 } 286 %> 287 288 289 </div> 290 </body> 291 </html>
zhengfenshu.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>真分数</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <form id="form1" name="form1" method="post" action="fenchuanzhi.jsp"> 20 <p> 21 <label for="textfield"></label> 22 </p> 23 <p> </p> 24 <p align="right"> </p> 25 <p align="left"> </p> 26 <p align="center"> </p> 27 <p align="center"> 分子分母的 最大值: 28 <input type="text" name="fenmax" id="fenmax" /> 29 <br> 30 题目个数:<input type="text" name="fengeshu" id="fengeshu" /> 31 <br> 32 选项:1有乘除法 2无乘除法 33 <br> 34 选项: 35 <input type="text" name="fenchoose" id="fenchoose" /> 36 </p> 37 <div align="center"> 38 <input type="submit" value="确定" value="fenchuanzhi.jsp"> 39 </div> 40 </form> 41 </body> 42 </html>
zhengfenshushizi,jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>真分数式子</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <div align="center"> 20 <%! 21 int feni=0; 22 String fenArray[]=new String[1000]; 23 24 class zhenfenshu 25 { 26 String refenshu; 27 28 //****最大公约**** 29 double getGcd(double m,double n){ 30 while(n > 0){ 31 double temp = m % n; 32 m = n; 33 n = temp; 34 } 35 return m; 36 } 37 //****最大公约**** 38 39 //***最小公倍数*** 40 double getLcm(double m,double n){ 41 double gcd = getGcd(m,n); 42 double result = m*n / gcd; 43 return result; 44 } 45 //***最小公倍数*** 46 String fun(int r ,int fun) 47 { 48 //1有乘除法2没有乘除法 49 String fu =""; 50 String shizi=""; 51 int a=(int)(Math.random()*(r+1)); 52 int b=(int)(Math.random()*(r+1)); 53 int c=(int)(Math.random()*(r+1)); 54 int d=(int)(Math.random()*(r+1)); 55 int e=(int)(Math.random()*4); 56 57 //1有乘除法****1 58 if(fun==1) 59 { 60 if(e==0) 61 { 62 fu="+"; 63 while(a>=b||c>=d||b==0||d==0) 64 { 65 a=(int)(Math.random()*(r+1)); 66 b=(int)(Math.random()*(r+1)); 67 c=(int)(Math.random()*(r+1)); 68 d=(int)(Math.random()*(r+1)); 69 } 70 //约分 71 int aa=(int) getGcd(a,b); 72 int cc=(int) getGcd(c,d); 73 a=a/aa; b=b/aa; 74 c=c/cc; d=d/cc; 75 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 76 int gongbei=(int) getLcm(b,d); 77 a=a*(gongbei/b); 78 c=c*(gongbei/d); 79 a=a+c; 80 int t=(int) getGcd(a,gongbei); 81 a=a/t; 82 gongbei=gongbei/t; 83 if(a==gongbei) 84 refenshu="1"; 85 else if(a==0) 86 refenshu="0"; 87 else if(a>gongbei) 88 { 89 int s=a%gongbei; 90 refenshu=1+"’"+s+"/"+gongbei; 91 } 92 else 93 refenshu=a+"/"+gongbei; 94 95 } 96 if(e==1) 97 { 98 fu="-"; 99 double y=getLcm(b,d); 100 double a1=y/b; 101 double c1=y/d; 102 double a2=a*a1; 103 double c2=c*c1; 104 while(a>=b||c>=d||b==0||d==0||a2<c2) 105 { 106 a=(int)(Math.random()*(r+1)); 107 b=(int)(Math.random()*(r+1)); 108 c=(int)(Math.random()*(r+1)); 109 d=(int)(Math.random()*(r+1)); 110 y=getLcm(b,d); 111 a1=y/b; 112 c1=y/d; 113 a2=a*a1; 114 c2=c*c1; 115 } 116 int aa=(int) getGcd(a,b); 117 int cc=(int) getGcd(c,d); 118 a=a/aa; b=b/aa; 119 c=c/cc; d=d/cc; 120 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 121 int gongbei=(int) getLcm(b,d); 122 a=a*(gongbei/b); 123 c=c*(gongbei/d); 124 a=a-c; 125 int t=(int) getGcd(a,gongbei); 126 a=a/t; 127 gongbei=gongbei/t; 128 if(a==gongbei) 129 refenshu="1"; 130 else if(a==0) 131 refenshu="0"; 132 else 133 refenshu=a+"/"+gongbei; 134 } 135 if(e==2) 136 { 137 fu="×"; 138 while(a>=b||c>=d||b==0||d==0) 139 { 140 a=(int)(Math.random()*(r+1)); 141 b=(int)(Math.random()*(r+1)); 142 c=(int)(Math.random()*(r+1)); 143 d=(int)(Math.random()*(r+1)); 144 } 145 int aa=(int) getGcd(a,b); 146 int cc=(int) getGcd(c,d); 147 a=a/aa; b=b/aa; 148 c=c/cc; d=d/cc; 149 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 150 a=a*c; 151 b=b*d; 152 int flag1=(int) getGcd(a,b); 153 a=a/flag1;b=b/flag1; 154 if(a==0) 155 refenshu="0"; 156 else 157 refenshu=a+"/"+b; 158 } 159 if(e==3) 160 { 161 fu="÷"; 162 while(a>=b||c>=d||b==0||d==0||c==0) 163 { 164 a=(int)(Math.random()*(r+1)); 165 b=(int)(Math.random()*(r+1)); 166 c=(int)(Math.random()*(r+1)); 167 d=(int)(Math.random()*(r+1)); 168 } 169 int aa=(int) getGcd(a,b); 170 int cc=(int) getGcd(c,d); 171 a=a/aa; b=b/aa; 172 c=c/cc; d=d/cc; 173 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 174 a=a*d; 175 b=b*c; 176 int flag1=(int) getGcd(a,b); 177 a=a/flag1;b=b/flag1; 178 if(a==0) 179 refenshu="0"; 180 else if(a==b) 181 refenshu="1"; 182 else if(b==1) 183 refenshu=a+""; 184 else if(a>b) 185 { 186 int s=a%b; 187 int s1=a/b; 188 refenshu=s1+"’"+s+"/"+b; 189 } 190 else 191 refenshu=a+"/"+b; 192 } 193 } 194 195 //2没有有乘除法***2 196 if(fun==2) 197 { 198 if(e==0) 199 { 200 fu="+"; 201 while(a>=b||c>=d||b==0||d==0) 202 { 203 a=(int)(Math.random()*(r+1)); 204 b=(int)(Math.random()*(r+1)); 205 c=(int)(Math.random()*(r+1)); 206 d=(int)(Math.random()*(r+1)); 207 } 208 int aa=(int) getGcd(a,b); 209 int cc=(int) getGcd(c,d); 210 a=a/aa; b=b/aa; 211 c=c/cc; d=d/cc; 212 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 213 int gongbei=(int) getLcm(b,d); 214 a=a*(gongbei/b); 215 c=c*(gongbei/d); 216 a=a+c; 217 int t=(int) getGcd(a,gongbei); 218 a=a/t; 219 gongbei=gongbei/t; 220 if(a==gongbei) 221 refenshu="1"; 222 else if(a==0) 223 refenshu="0"; 224 else if(a>gongbei) 225 { 226 int s=a%gongbei; 227 refenshu=1+"’"+s+"/"+gongbei; 228 } 229 else 230 refenshu=a+"/"+gongbei; 231 } 232 if(e==1) 233 { 234 fu="-"; 235 double y=getLcm(b,d); 236 double a1=y/b; 237 double c1=y/d; 238 double a2=a*a1; 239 double c2=c*c1; 240 while(a>=b||c>=d||b==0||d==0||a2<c2) 241 { 242 a=(int)(Math.random()*(r+1)); 243 b=(int)(Math.random()*(r+1)); 244 c=(int)(Math.random()*(r+1)); 245 d=(int)(Math.random()*(r+1)); 246 y=getLcm(b,d); 247 a1=y/b; 248 c1=y/d; 249 a2=a*a1; 250 c2=c*c1; 251 } 252 int aa=(int) getGcd(a,b); 253 int cc=(int) getGcd(c,d); 254 a=a/aa; b=b/aa; 255 c=c/cc; d=d/cc; 256 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 257 int gongbei=(int) getLcm(b,d); 258 a=a*(gongbei/b); 259 c=c*(gongbei/d); 260 a=a-c; 261 int t=(int) getGcd(a,gongbei); 262 a=a/t; 263 gongbei=gongbei/t; 264 if(a==gongbei) 265 refenshu="1"; 266 else if(a==0) 267 refenshu="0"; 268 else 269 refenshu=a+"/"+gongbei; 270 } 271 if(e==2) 272 { 273 fu="+"; 274 while(a>=b||c>=d||b==0||d==0) 275 { 276 a=(int)(Math.random()*(r+1)); 277 b=(int)(Math.random()*(r+1)); 278 c=(int)(Math.random()*(r+1)); 279 d=(int)(Math.random()*(r+1)); 280 } 281 int aa=(int) getGcd(a,b); 282 int cc=(int) getGcd(c,d); 283 a=a/aa; b=b/aa; 284 c=c/cc; d=d/cc; 285 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 286 int gongbei=(int) getLcm(b,d); 287 a=a*(gongbei/b); 288 c=c*(gongbei/d); 289 a=a+c; 290 int t=(int) getGcd(a,gongbei); 291 a=a/t; 292 gongbei=gongbei/t; 293 if(a==gongbei) 294 refenshu="1"; 295 else if(a==0) 296 refenshu="0"; 297 else if(a>gongbei) 298 { 299 int s=a%gongbei; 300 refenshu=1+"’"+s+"/"+gongbei; 301 } 302 else 303 refenshu=a+"/"+gongbei; 304 } 305 if(e==3) 306 { 307 fu="-"; 308 double y=getLcm(b,d); 309 double a1=y/b; 310 double c1=y/d; 311 double a2=a*a1; 312 double c2=c*c1; 313 while(a>=b||c>=d||b==0||d==0||a2<c2) 314 { 315 a=(int)(Math.random()*(r+1)); 316 b=(int)(Math.random()*(r+1)); 317 c=(int)(Math.random()*(r+1)); 318 d=(int)(Math.random()*(r+1)); 319 y=getLcm(b,d); 320 a1=y/b; 321 c1=y/d; 322 a2=a*a1; 323 c2=c*c1; 324 } 325 int aa=(int) getGcd(a,b); 326 int cc=(int) getGcd(c,d); 327 a=a/aa; b=b/aa; 328 c=c/cc; d=d/cc; 329 shizi=a+"/"+b+" "+fu+" "+c+"/"+d; 330 int gongbei=(int) getLcm(b,d); 331 a=a*(gongbei/b); 332 c=c*(gongbei/d); 333 a=a-c; 334 int t=(int) getGcd(a,gongbei); 335 a=a/t; 336 gongbei=gongbei/t; 337 if(a==gongbei) 338 refenshu="1"; 339 else if(a==0) 340 refenshu="0"; 341 else 342 refenshu=a+"/"+gongbei; 343 } 344 } 345 return shizi; 346 } 347 } 348 %> 349 <% 350 351 //加载JDBC驱动 352 String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; 353 //连接服务器和数据库sample 354 String dbpath = "jdbc:sqlserver://localhost:1433; DatabaseName=test"; 355 String username = "sa"; //默认用户名 356 String password = "19961114.wfb"; //密码 357 358 Connection con = null; //定义一个SQL server链接对象 359 Class.forName(driverName).newInstance(); //SQL server驱动 360 con = DriverManager.getConnection(dbpath, username, password); //链接本地SQL server 361 java.sql.Statement stmt; //创建声明 362 stmt = con.createStatement(); 363 int fenmax=Integer.parseInt(String.valueOf(session.getAttribute("fenmax"))); 364 int fenchoose=Integer.parseInt(String.valueOf(session.getAttribute("fenchoose"))); 365 int fengeshu=Integer.parseInt(String.valueOf(session.getAttribute("fengeshu"))); 366 session.setAttribute("fengeshu1", fengeshu); 367 //String daan=request.getParameter("daan"); 368 369 int zhengque1=0,cuowu1=0; 370 int zhengque4[]=new int[fengeshu+10]; 371 int cuowu4[]=new int[fengeshu+10]; 372 zhenfenshu a = new zhenfenshu(); 373 //for(int i=0;i<geshu;i++) 374 %> 375 376 377 <% 378 if(feni<fengeshu) 379 { 380 fenArray[feni]=a.fun(fenmax,fenchoose); 381 if(feni>0) 382 { 383 for(int z=0;z<feni;z++) 384 { 385 if((fenArray[z].equals(fenArray[feni]))) 386 { 387 fenArray[feni]=a.fun(fenmax,fenchoose); 388 z=-1; 389 } 390 } 391 } 392 out.println(feni+1+": "+fenArray[feni]+" = "); 393 394 %> 395 <% //将题目和答案写入数据库表 396 String sql="INSERT INTO 四则运算题目1 (shizi,result) VALUES ('"+fenArray[feni]+" = "+"','"+a.refenshu+"')"; 397 398 //out.println("<script language = 'javaScript'> alert('"+shi+"');</script>"); 399 stmt.executeUpdate(sql); 400 401 %> 402 <br> 403 404 </div> 405 <form id="form1" name="form1" method="post" action="zhenfenshusjk.jsp"> 406 <p> </p> 407 <p align="center">答案: 408 <input type="text" name="daan" id="daan" /> 409 <% 410 String shi3=fenArray[feni]+" = "; 411 session.setAttribute("shi",shi3); 412 String rere3=a.refenshu; 413 session.setAttribute("rere",rere3); 414 //String daan3=request.getParameter("daan"); 415 //session.setAttribute("daan",daan3); 416 session.setAttribute("i2",feni); 417 418 feni++; 419 stmt.close(); 420 con.close(); 421 %> 422 <input type="submit" value="下一个" > 423 </p> 424 </form> 425 426 <div align="center"> 427 <% 428 //String daan3=request.getParameter("daan"); 429 430 //daan3=request.getParameter("daan"); 431 //session.setAttribute("daan",daan3); 432 433 %> 434 435 <% 436 } 437 else 438 { 439 feni=0; 440 %> 441 </div> 442 <form action="fenchakan.jsp" method="post" > 443 <div align="center"> 444 <% 445 String correct=String.valueOf(session.getAttribute("correct1")); 446 String wrong=String.valueOf(session.getAttribute("wrong1")); 447 %> 448 <input type="submit" value="查看成绩" name="button" align="middle"> 449 </div> 450 </form> 451 <div align="center"> 452 <% 453 } 454 %> 455 456 457 </div> 458 </body> 459 </html>
kuohaochakan.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>成绩查看</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 String kuohaocorrect=String.valueOf(session.getAttribute("kuohaocorrect1")); 21 String kuohaowrong=String.valueOf(session.getAttribute("kuohaowrong1")); 22 out.print("正确的题号:"+kuohaocorrect+" 错误的题号:"+kuohaowrong); 23 out.println("<script language = 'javaScript'> alert('点击确定返回开始页面!');</script>"); 24 response.setHeader("refresh","0;url = choose.jsp"); 25 %> 26 27 </body> 28 </html>
kuohaochuanzhi.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.util.regex.Pattern, java.util.regex.Matcher"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>传值</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 21 22 String kuohaomax = request.getParameter("kuohaomax"); 23 session.setAttribute("kuohaomax",kuohaomax); 24 String kuohaomin = request.getParameter("kuohaomin"); 25 session.setAttribute("kuohaomin",kuohaomin); 26 String kuohaogeshu = request.getParameter("kuohaogeshu"); 27 session.setAttribute("kuohaogeshu",kuohaogeshu); 28 29 Pattern pattern = Pattern.compile("[0-9]*"); 30 Matcher isNum = pattern.matcher(kuohaomax); 31 Matcher isNum2 = pattern.matcher(kuohaomin); 32 Matcher isNum3 = pattern.matcher(kuohaogeshu); 33 if( (!isNum.matches())||(!isNum3.matches())||(!isNum2.matches())) 34 { 35 out.println("<script language = 'javaScript'> alert('输入错误,点击确定重新输入!!!');</script>"); 36 response.setHeader("refresh","0;url = daikuohao.jsp"); 37 } 38 else 39 { 40 response.setHeader("refresh","0;url = daikuohaoshizi.jsp"); 41 } 42 %> 43 </body> 44 </html>
kuohaosjk.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>判断答案</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 <%! String kuohaocorrect="",kuohaowrong="";%> 18 <% 19 20 String daan3=request.getParameter("daan"); 21 String shi5=String.valueOf(session.getAttribute("shi")); 22 int geshu5=Integer.parseInt(String.valueOf(session.getAttribute("kuohaogeshu1"))); 23 int i5=Integer.parseInt(String.valueOf(session.getAttribute("i2"))); 24 int i6=i5+1; 25 String rere5=String.valueOf(session.getAttribute("rere")); 26 if(rere5.equals(daan3)) 27 { 28 //out.println("恭喜你,回答正确!!!"); 29 kuohaocorrect=kuohaocorrect+i6+" "; 30 out.println("<script language = 'javaScript'> alert('恭喜你,回答正确!!!');</script>"); 31 response.setHeader("refresh","0;url = daikuohaoshizi.jsp"); 32 } 33 else 34 { 35 //out.println("回答错误!正确答案为:"+result); 36 kuohaowrong=kuohaowrong+i6+" "; 37 out.println("<script language = 'javaScript'> alert('回答错误!!!正确答案:"+rere5+"');</script>"); 38 response.setHeader("refresh","0;url = daikuohaoshizi.jsp"); 39 } 40 String kuohaocorrect2=kuohaocorrect; 41 String kuohaowrong2=kuohaowrong; 42 if(i5==geshu5-1) 43 { 44 kuohaocorrect="";kuohaowrong=""; 45 } 46 session.setAttribute("kuohaocorrect1",kuohaocorrect2); 47 session.setAttribute("kuohaowrong1",kuohaowrong2); 48 %> 49 </body> 50 </html>
chuanzhi.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.util.regex.Pattern, java.util.regex.Matcher"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>传值</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 21 22 String min = request.getParameter("min"); 23 session.setAttribute("min",min); 24 String max = request.getParameter("max"); 25 session.setAttribute("max",max); 26 String choose = request.getParameter("choose"); 27 session.setAttribute("choose",choose); 28 String geshu = request.getParameter("geshu"); 29 session.setAttribute("geshu",geshu); 30 31 Pattern pattern = Pattern.compile("[0-9]*"); 32 Pattern pattern1 = Pattern.compile("[1-3]"); 33 Matcher isNum = pattern.matcher(min); 34 Matcher isNum2 = pattern.matcher(max); 35 Matcher isNum3 = pattern.matcher(geshu); 36 Matcher isNum4 = pattern1.matcher(choose); 37 if( (!isNum.matches())||(!isNum2.matches())||(!isNum3.matches())||(!isNum4.matches())) 38 { 39 out.println("<script language = 'javaScript'> alert('输入错误,点击确定重新输入!!!');</script>"); 40 response.setHeader("refresh","0;url = zhengshu.jsp"); 41 } 42 else 43 { 44 response.setHeader("refresh","0;url = zhengshushizi.jsp"); 45 } 46 %> 47 </body> 48 </html>
fenshuchuanzhi.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.util.regex.Pattern, java.util.regex.Matcher"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 7 <title>传值</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 21 22 String fenmax = request.getParameter("fenmax"); 23 session.setAttribute("fenmax",fenmax); 24 String fenchoose = request.getParameter("fenchoose"); 25 session.setAttribute("fenchoose",fenchoose); 26 String fengeshu = request.getParameter("fengeshu"); 27 session.setAttribute("fengeshu",fengeshu); 28 29 Pattern pattern = Pattern.compile("[0-9]*"); 30 Pattern pattern1 = Pattern.compile("[1-2]"); 31 Matcher isNum = pattern.matcher(fenmax); 32 Matcher isNum3 = pattern.matcher(fengeshu); 33 Matcher isNum4 = pattern1.matcher(fenchoose); 34 if( (!isNum.matches())||(!isNum3.matches())||(!isNum4.matches())) 35 { 36 out.println("<script language = 'javaScript'> alert('输入错误,点击确定重新输入!!!');</script>"); 37 response.setHeader("refresh","0;url = zhenfenshu.jsp"); 38 } 39 else 40 { 41 response.setHeader("refresh","0;url = zhenfenshushizi.jsp"); 42 } 43 %> 44 </body> 45 </html>
fenshuchakan.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>成绩查看</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 String fencorrect=String.valueOf(session.getAttribute("fencorrect1")); 21 String fenwrong=String.valueOf(session.getAttribute("fenwrong1")); 22 out.print("正确的题号:"+fencorrect+" 错误的题号:"+fenwrong); 23 out.println("<script language = 'javaScript'> alert('点击确定返回开始页面!');</script>"); 24 response.setHeader("refresh","0;url = choose.jsp"); 25 %> 26 27 </body> 28 </html>
chakan.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>成绩查看</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <% 20 String correct=String.valueOf(session.getAttribute("correct1")); 21 String wrong=String.valueOf(session.getAttribute("wrong1")); 22 out.print("正确的题号:"+correct+" 错误的题号:"+wrong); 23 out.println("<script language = 'javaScript'> alert('点击确定返回开始页面!');</script>"); 24 response.setHeader("refresh","0;url = choose.jsp"); 25 %> 26 27 </body> 28 </html>
daikuohao.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>带括号</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <p> </p> 20 <p> </p> 21 <p> </p> 22 <p> </p> 23 <p> </p> 24 <form id="form1" name="form1" method="post" action="kuohaochuanzhi.jsp"> 25 <label for="textfield"></label> 26 <div align="center">最小值: 27 <input type="text" name="kuohaomin" id="fenmin" /> 28 <br> 29 最大值:<input type="text" name="kuohaomax" id="kuohaomax" /> 30 <br> 31 题目个数:<input type="text" name="kuohaogeshu" id="kuohaogeshu" /> 32 <br> 33 </div> 34 <div align="center"> 35 <input type="submit" value="确定" value="kuohaochuanzhi.jsp"> 36 </div> 37 </form> 38 </body> 39 </html>
daikuohaoshizi.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>带括号式子</title> 8 <style type="text/css"> 9 body,td,th { 10 font-size: 24px; 11 } 12 body { 13 background-color: #0CF; 14 background-image: url(背景图片.bmp); 15 } 16 </style> 17 </head> 18 <body> 19 <div align="center"> 20 <%! 21 int kuohaoi=0; 22 String kuohaoArray[]=new String[1000]; 23 class daikuohao 24 { 25 //保存整数结果 26 int re; 27 //保存整数带余数的结果 28 String re1; 29 //保存三个整数公式的结果 30 int resan; 31 String function(int r ,int q, int fun) 32 { 33 //1有乘除法 2加减无负数 3除法无余数(12,1,0) 34 String fu =""; 35 String shizi=""; 36 int a=(int)(Math.random()*(r)%(r-q+1)+q); 37 int b=(int)(Math.random()*(r)%(r-q+1)+q); 38 int c=(int)(Math.random()*4); 39 40 //1乘除法 2除法无余数****12 41 if(fun==12) 42 { 43 if(c==0) 44 { 45 fu="+"; 46 shizi=a+" "+fu+" "+b; 47 re=a+b; 48 re1=String.valueOf(re); 49 } 50 if(c==1) 51 { 52 fu="-"; 53 //排除负数可能性 54 while(a-b<0) 55 { 56 a=(int)(Math.random()*(r)%(r-q+1)+q); 57 b=(int)(Math.random()*(r)%(r-q+1)+q); 58 } 59 shizi=a+" "+fu+" "+b; 60 re=a-b; 61 re1=String.valueOf(re); 62 } 63 if(c==2) 64 { 65 fu="×"; 66 shizi=a+" "+fu+" "+b; 67 re=a*b; 68 re1=String.valueOf(re); 69 } 70 if(c==3) 71 { 72 fu="÷"; 73 //排除分母为0的可能性和余数的可能性 74 while(b==0||a%b!=0) 75 { 76 a=(int)(Math.random()*(r)%(r-q+1)+q); 77 b=(int)(Math.random()*(r)%(r-q+1)+q); 78 } 79 re=a/b; 80 shizi=a+" "+fu+" "+b; 81 re1=String.valueOf(re); 82 } 83 } 84 85 86 //1乘除法 2除法无余数****1 87 if(fun==1) 88 { 89 if(c==0) 90 { 91 fu="+"; 92 re=a+b; 93 re1=String.valueOf(re); 94 shizi=a+" "+fu+" "+b; 95 } 96 if(c==1) 97 { 98 fu="-"; 99 //排除负数可能性 100 while(a-b<0) 101 { 102 a=(int)(Math.random()*(r)%(r-q+1)+q); 103 b=(int)(Math.random()*(r)%(r-q+1)+q); 104 } 105 shizi=a+" "+fu+" "+b; 106 re=a-b; 107 re1=String.valueOf(re); 108 } 109 if(c==2) 110 { 111 fu="×"; 112 re=a*b; 113 re1=String.valueOf(re); 114 shizi=a+" "+fu+" "+b; 115 } 116 if(c==3) 117 { 118 fu="÷"; 119 //排除分母为0的可能性 120 while(b==0) 121 { 122 b=(int)(Math.random()*(r)%(r-q+1)+q); 123 } 124 re=a/b; 125 if(a%b!=0) 126 { 127 int flag1=a%b; 128 re1=String.valueOf(re)+"..."+String.valueOf(flag1); 129 } 130 else 131 re1=String.valueOf(re); 132 shizi=a+" "+fu+" "+b; 133 } 134 } 135 136 //1乘除法 2除法无余数****0 137 if(fun==0) 138 { 139 if(c==0) 140 { 141 fu="+"; 142 re=a+b; 143 re1=String.valueOf(re); 144 shizi=a+" "+fu+" "+b; 145 } 146 if(c==1) 147 { 148 fu="-"; 149 //排除负数可能性 150 while(a-b<0) 151 { 152 a=(int)(Math.random()*(r)%(r-q+1)+q); 153 b=(int)(Math.random()*(r)%(r-q+1)+q); 154 } 155 re=a-b; 156 re1=String.valueOf(re); 157 shizi=a+" "+fu+" "+b; 158 } 159 if(c==2) 160 { 161 fu="+"; 162 re=a+b; 163 re1=String.valueOf(re); 164 shizi=a+" "+fu+" "+b; 165 } 166 if(c==3) 167 { 168 fu="-"; 169 //排除负数可能性 170 while(a-b<0) 171 { 172 a=(int)(Math.random()*(r)%(r-q+1)+q); 173 b=(int)(Math.random()*(r)%(r-q+1)+q); 174 } 175 re=a-b; 176 re1=String.valueOf(re); 177 shizi=a+" "+fu+" "+b; 178 } 179 } 180 return shizi; 181 } 182 //***************生成整数公式的函数********************** 183 String sgongshi(int r,int q) 184 { 185 String shi,shizi=""; 186 int a=(int)(Math.random()*(r)%(r-q+1)+q); 187 int e=(int)(Math.random()*4); 188 shi=function(r,q,12); 189 if(e==0) 190 { 191 int f=(int)(Math.random()*4); 192 if(f==1||f==0) 193 { 194 shizi=a+" + "+"( "+shi+" )"; 195 resan=a+re; 196 } 197 if(f==2||f==3) 198 { 199 shizi="( "+shi+" )"+" + "+a; 200 resan=a+re; 201 } 202 } 203 if(e==1) 204 { 205 int f=(int)(Math.random()*4); 206 if(f==1||f==0) 207 { 208 while(a-re<0) 209 { 210 shi=function(r,q,12); 211 } 212 shizi=a+" - "+"( "+shi+" )"; 213 resan=a-re; 214 } 215 if(f==2||f==3) 216 { 217 while(a-re>0) 218 { 219 shi=function(r,q,12); 220 } 221 shizi="( "+shi+" )"+" - "+a; 222 resan=re-a; 223 } 224 } 225 if(e==2) 226 { 227 int f=(int)(Math.random()*4); 228 if(f==1||f==0) 229 { 230 shizi=a+" × "+"( "+shi+" )"; 231 resan=a*re; 232 } 233 if(f==2||f==3) 234 { 235 shizi="( "+shi+" )"+" × "+a; 236 resan=a*re; 237 } 238 } 239 if(e==3) 240 { 241 int f=(int)(Math.random()*4); 242 if(f==1||f==0) 243 { 244 while(re==0) 245 { 246 shi=function(r,q,12); 247 } 248 while(a%re!=0) 249 { 250 shi=function(r,q,12); 251 while(re==0) 252 { 253 shi=function(r,q,12); 254 } 255 } 256 shizi=a+" ÷ "+"( "+shi+" )"; 257 resan=a/re; 258 } 259 if(f==2||f==3) 260 { 261 while(a==0) 262 { 263 a=(int)(Math.random()*(r)%(r-q+1)+q); 264 } 265 while(re%a!=0) 266 { 267 shi=function(r,q,12); 268 } 269 shizi="( "+shi+" )"+" ÷ "+a; 270 resan=re/a; 271 } 272 } 273 return shizi; 274 } 275 //*****生成三个数的式子的函数****** 276 } 277 %> 278 279 <% 280 //加载JDBC驱动 281 String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; 282 //连接服务器和数据库sample 283 String dbpath = "jdbc:sqlserver://localhost:1433; DatabaseName=test"; 284 String username = "sa"; //默认用户名 285 String password = "19961114.wfb"; //密码 286 287 Connection con = null; //定义一个SQL server链接对象 288 Class.forName(driverName).newInstance(); //SQL server驱动 289 con = DriverManager.getConnection(dbpath, username, password); //链接本地SQL server 290 java.sql.Statement stmt; //创建声明 291 stmt = con.createStatement(); 292 int kuohaomax=Integer.parseInt(String.valueOf(session.getAttribute("kuohaomax"))); 293 int kuohaomin=Integer.parseInt(String.valueOf(session.getAttribute("kuohaomin"))); 294 int kuohaogeshu=Integer.parseInt(String.valueOf(session.getAttribute("kuohaogeshu"))); 295 session.setAttribute("kuohaogeshu1", kuohaogeshu); 296 //String daan=request.getParameter("daan"); 297 298 int zhengque1=0,cuowu1=0; 299 int zhengque4[]=new int[kuohaogeshu+10]; 300 int cuowu4[]=new int[kuohaogeshu+10]; 301 daikuohao a = new daikuohao(); 302 //for(int i=0;i<geshu;i++) 303 %> 304 305 306 <% 307 if(kuohaoi<kuohaogeshu) 308 { 309 kuohaoArray[kuohaoi]=a.sgongshi(kuohaomax,kuohaomin); 310 if(kuohaoi>0) 311 { 312 for(int z=0;z<kuohaoi;z++) 313 { 314 if((kuohaoArray[z].equals(kuohaoArray[kuohaoi]))) 315 { 316 kuohaoArray[kuohaoi]=a.sgongshi(kuohaomax,kuohaomin); 317 z=-1; 318 } 319 } 320 } 321 out.println(kuohaoi+1+": "+kuohaoArray[kuohaoi]+" = "); 322 323 %> 324 <% //将题目和答案写入数据库表 325 String sql="INSERT INTO 四则运算题目3 (shizi,result) VALUES ('"+kuohaoArray[kuohaoi]+" = "+"','"+a.resan+"')"; 326 327 //out.println("<script language = 'javaScript'> alert('"+shi+"');</script>"); 328 stmt.executeUpdate(sql); 329 330 %> 331 <br> 332 333 </div> 334 <form id="form1" name="form1" method="post" action="kuohaosjk.jsp"> 335 <div align="center"> 336 <p> </p> 337 <p>答案: 338 <input type="text" name="daan" id="daan" /> 339 <% 340 String shi3=kuohaoArray[kuohaoi]+" = "; 341 session.setAttribute("shi",shi3); 342 int rere3=a.resan; 343 session.setAttribute("rere",rere3); 344 //String daan3=request.getParameter("daan"); 345 //session.setAttribute("daan",daan3); 346 session.setAttribute("i2",kuohaoi); 347 348 kuohaoi++; 349 stmt.close(); 350 con.close(); 351 %> 352 <input type="submit" value="下一个" > 353 </p> 354 </div> 355 </form> 356 357 <div align="center"> 358 <% 359 //String daan3=request.getParameter("daan"); 360 361 //daan3=request.getParameter("daan"); 362 //session.setAttribute("daan",daan3); 363 364 %> 365 366 <% 367 } 368 else 369 { 370 kuohaoi=0; 371 %> 372 </div> 373 <form action="kuohaochakan.jsp" method="post" > 374 <div align="center"> 375 <% 376 String correct=String.valueOf(session.getAttribute("correct1")); 377 String wrong=String.valueOf(session.getAttribute("wrong1")); 378 %> 379 <input type="submit" value="查看成绩" name="button" align="middle"> 380 </div> 381 </form> 382 <div align="center"> 383 <% 384 } 385 %> 386 387 388 </div> 389 </body> 390 </html>
运行结果截图:
编程的总结和体会:
在这个构建整个网页的的过程中,我渐渐体会到了程序代码和一个软件之间的差别,刚开始写小的程序时我可以在一个文件或者几个文件里写,但随着规模大的扩大渐渐地构建整个程序有了困难,除了差错无法准确的定位,并且存在一些逻辑上的错误,更是无法及时纠正,中间出现可很多错误,我也向同学和朋友请教问题所在,也借鉴了同学的意见和建议,做出了这个简单的网页程序,,中间还有许多小的bug和我也没有发现的错误。我会记住这个我的第一个小小的项目,在以后的学习和工作里改正我的错误。以后我会有提高的。
PSP2.1