博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单的四则运算网页版
阅读量:6174 次
发布时间:2019-06-21

本文共 7166 字,大约阅读时间需要 23 分钟。

四、源代码

欢迎界面

1  2  3  4 <%@ page language="java" contentType="text/html; charset=UTF-8" 5     pageEncoding="UTF-8"%> 6 
7 小学二年级算式计算 8 9 10

小学二年级算式计算

11

本页仅供二年级的小同学测试使用,共60道100以内加减乘除算式计算题,计时8分钟。

12
15 16

题目展示界面

1 <%@page import="CC.GradeTwo" %> 2  3  4  5 <%@ page language="java" contentType="text/html; charset=UTF-8" 6     pageEncoding="UTF-8"%> 7 
8 27 小学二年级算式计算28 29 <%30 String str = null;31 %>32 33 34 <%35 request.setCharacterEncoding("utf-8");36 %>37
38
39
40
41
42
43
44
45
46 <% GradeTwo.clear();47 for(int i = 1;i<=60;++i) { 48 str = GradeTwo.getPoly();49 50 %>51
52 <%53 }54 %>55
56
共60题,注意用时
第<%=i %>题 <%=str %>
57
58 59

结果展示界面

1  2  3  4 <%@page import="CC.GradeTwo" %> 5 <%@ page language="java" contentType="text/html; charset=UTF-8" 6     pageEncoding="UTF-8"%> 7 
8 答案 9 10 11

答题结果

12 <%13 int[]end = (int[])(request.getAttribute("result"));14 String str[] = (String[])request.getAttribute("result1");15 %>16
17
18
19
20
答对: <%=end[0] %>
答错: <%=end[1] %>
未答: <%=end[2] %>

21

答题情况

22
23
24 <% 25 String color = "";26 for(int i = 0;i<60;++i){27 if(GradeTwo.key.get(i).equals(str[i])){28 %>29
30 <%}31 else{32 %>33
34 35 <%36 }37 }38 %>39
题目 提交答案 正确答案
<%=GradeTwo.pro.get(i) %> <%=str[i] %> <%=GradeTwo.key.get(i) %>
<%=GradeTwo.pro.get(i) %> <%=str[i] %> <%=GradeTwo.key.get(i) %>
40
41 42

标头:

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 
4
" border="1" cellpadding="4" cellspacing="0"> 5 6
" color="#ffffff"> 7
8
9
10
<%=request.getParameter("title") %>
<%=request.getParameter("body") %>

产生表达式的Java文件:

1 package CC;  2   3 import java.util.ArrayList;  4 import java.util.List;  5 import java.util.Random;  6 import java.util.Set;  7 import java.util.Vector;  8   9 public class GradeTwo { 10     private static String opera = "+-*/"; 11     public static Vector
pro = new Vector
(); 12 public static Vector
key = new Vector
(); 13 public static void clear() { 14 pro.clear(); 15 key.clear(); 16 } 17 public static int isInteger(int c1, int c2, char opera) { 18 int result = 0; 19 int result1 = 0; 20 switch (opera) { 21 case '+': 22 result = c1 + c2; 23 break; 24 case '-': 25 result = c1 - c2; 26 break; 27 case '*': 28 result = c1 * c2; 29 break; 30 case '/': 31 result = c1 / c2; 32 result1 = c1 % c2; 33 break; 34 } 35 if (result >= 0 && result <= 100 && result1 == 0) 36 return result; 37 else 38 return -1; 39 } 40 41 public static String getPoly() { 42 String poly = ""; 43 // Random random = new Random(); 44 // 45 // int c1; 46 // int c2; 47 // int result; 48 // char operac; 49 // boolean flag = true; 50 // do { 51 // c1 = random.nextInt(100) + 1; 52 // c2 = random.nextInt(100) + 1; 53 // operac = opera.charAt(random.nextInt(4)); 54 // if (operac == '*') 55 // poly = c1 + " × " + c2 + " = "; 56 // if (operac == '/') 57 // poly = c1 + " ÷ " + c2 + " = "; 58 // if (operac == '+') 59 // poly = c1 + " + " + c2 + " = "; 60 // if (operac == '-') 61 // poly = c1 + " - " + c2 + " = "; 62 // /*for (int i = 0;i

Servlet:

1 package Servlet; 2  3 import CC.GradeTwo; 4 import javax.servlet.http.HttpServlet; 5 import java.io.IOException; 6 import javax.servlet.ServletException; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 11 12 public class GradeServlet extends HttpServlet{13     public void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{14         String method = req.getParameter("method");15         if(method.equals("end"))end(req,resp); 16     }17     public void end(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{18            String[]keys = req.getParameterValues("list");19            req.setAttribute("result",GradeTwo.end(keys));20            for(int i = 0;i

Filter:防止直接进入结果界面:

1 package Servlet; 2  3 import javax.servlet.http.HttpServlet; 4 import java.io.IOException; 5  6 import javax.servlet.Filter; 7 import javax.servlet.FilterChain; 8 import javax.servlet.FilterConfig; 9 import javax.servlet.ServletException;10 import javax.servlet.ServletRequest;11 import javax.servlet.ServletResponse;12 import javax.servlet.http.HttpServletRequest;13 import javax.servlet.http.HttpServletResponse;14 15 public class KeyFilter implements Filter{16     protected FilterConfig filterConfig;17     @Override18     public void destroy() {19         // TODO 自动生成的方法存根20         filterConfig = null;21     }22 23     @Override24     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)25             throws IOException, ServletException {26         // TODO 自动生成的方法存根27           HttpServletRequest req = (HttpServletRequest)request;28           HttpServletResponse resp = (HttpServletResponse)response;29           String reqURL = req.getServletPath();30           if(reqURL.equals("/result.jsp")) {31               resp.sendRedirect("index.jsp");32               return;33           }34           chain.doFilter(request,response);35     }36 37     @Override38     public void init(FilterConfig filterConfig) throws ServletException {39         // TODO 自动生成的方法存根40          this.filterConfig = filterConfig;41     }42      43 }

xml文件:(需要添加)

1   
GradeCal
2
3
GradeServlet
4
Servlet.GradeServlet
5
6
7
GradeServlet
8
/Servlet/GradeServlet
9
10
11
KeyFilter
12
Servlet.KeyFilter
13
14
15
KeyFilter
16
/*
17

 

------------------------------------------------------------------------

END

转载于:https://www.cnblogs.com/messi2017/p/7994304.html

你可能感兴趣的文章
Javascript动态执行JS(new Function与eval比较)
查看>>
量子计算的理论发展(二)
查看>>
TruckWings推全新气动系统卡车,或将节约至少5%的燃油量
查看>>
不只是一朵“云”,蚂蚁金融科技如何助力云上移动金融?
查看>>
eBPF监控工具bcc系列四工具argdist
查看>>
杨义先:大数据的道性
查看>>
Fitbit表高兴太早,廉价手环和智能手表的威胁就在眼前
查看>>
开启Windows 10上帝模式快速查找所有的系统设置
查看>>
linux安装redis
查看>>
JavaScript 编程精解 中文第三版 十二、项目:编程语言
查看>>
AI时代:匿名不等于隐私保护
查看>>
ThinkPHP 5使用OSS
查看>>
惠享生活、创想未来 2016上海智慧城市体验周今日开幕
查看>>
hdu 1166 敌兵布阵 (树状数组)
查看>>
CRITICAL_SECTION 学习
查看>>
c++ builder 中的 XMLDocument 类详解(4) - 攻取根目录下元素数
查看>>
在gridview控件添加checkbox
查看>>
MS CRM 2011 RetrieveMultiple with JScript JQuery Silverlight LINQ FetchXML and QueryExpression
查看>>
||(或者) &amp;&amp;(并且)
查看>>
nginx 主动式后端服务器健康检查
查看>>