博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单的四则运算网页版
阅读量:6175 次
发布时间: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

你可能感兴趣的文章
StringBuilder用法小结
查看>>
对‘初学者应该选择哪种编程语言’的回答——计算机达人成长之路(38)
查看>>
如何申请开通微信多客服功能
查看>>
Sr_C++_Engineer_(LBS_Engine@Global Map Dept.)
查看>>
非监督学习算法:异常检测
查看>>
《OSPF和IS-IS详解》一2.7 BGP-IGP的路由交换
查看>>
App开发中甲乙方冲突会闹出啥后果?H5 APP 开发可以改变现状吗
查看>>
python知识点总结---函数
查看>>
centos7 mysql数据库的安装与使用
查看>>
jquery的checkbox,radio,select等方法总结
查看>>
Linux coredump
查看>>
iphone开发实现单选框
查看>>
keymaster -快捷键管理器
查看>>
Ubuntu 10.04安装水晶(Mercury)无线网卡驱动
查看>>
Apache服务器SSL双向认证配置
查看>>
论数据库访问组件的选择--火地晋大作读后感
查看>>
php socket服务端和OC客户端(简单的测试)
查看>>
算法:基于 RingBuffer 的 Deque 实现
查看>>
Unity 物理引擎动力学关节
查看>>
黄聪:360浏览器、chrome开发扩展插件教程(1)开发Chrome Extenstion其实很简单
查看>>