jsp实验11 JavaBean

二、实验项目内容(实验题目)

编写代码,掌握javabean的用法。【参考课本 上机实验 5.5.2 】

三、源代码以及执行结果截图:

源代码:

Memory.java

package sea.water;

import java.util.ArrayList;

import java.util.Random;

public class Memory {

                   static ArrayList<String> list = new ArrayList<String>();

                   static {

                     list.add("★");

                     list.add("●");

                     list.add("▲");

                     list.add("■");

                     list.add("◆");

                   }

                   int grade = 5;

                   String testString;

                   boolean isGivenTestString = false;

                   public void setGrade(int n) {

                     grade = n;

                   }

                   public int getGrade() {

                     return grade;

                   }

                   public void giveTestString() {

                     StringBuffer buffer = new StringBuffer();

                     Random random = new Random();

                     for(int i=0;i<grade;i++) {

                            int index = random.nextInt(list.size());

                            String str = list.get(index);

                            buffer.append(str);

                     }

                     testString = new String(buffer);

                   }

                   public void setIsGivenTestString(boolean b) {

                     isGivenTestString = b;

                   }

                   public boolean getIsGivenTestString() {

                     return isGivenTestString;

                   }

                   public String getTestString() {

                     return testString;

                   }

}

choiceGrade.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<style type="text/css">

   #textStyle{

      font-family: 宋体;

      font-size: 26;

      color: blue;

   }

</style>

</head>

<body bgcolor="#ffccff">

   <form action="giveTest.jsp" id="textStyle" method="post">

      <input type="radio" name="grade" value="5" />初级

      <input type="radio" name="grade" value="7" checked="ok" />中级

      <input type="radio" name="grade" value="10" />高级

      <br><input type="submit" id="textStyle" value="提交" />

      <input type="reset" id="textStyle" value="重置" />

   </form>

</body>

</html>

giveTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<style type="text/css">

   #tomStyle{

      font-family: 宋体;

      font-size: 36;

      color: blue;

   }

</style>

</head>

<jsp:useBean id="memory" class="sea.water.Memory" scope="session" />

<body bgcolor="#ffccff">

   <%

      String grade = request.getParameter("grade");

      String testString = "";

      if(grade == null){

        memory.setGrade(memory.getGrade());

      }else{

        memory.setGrade(Integer.parseInt(grade));

      }

      if(memory.getIsGivenTestString() == false){

        memory.giveTestString();

        testString = memory.getTestString();

        memory.setIsGivenTestString(true);

      }

      else if(memory.getIsGivenTestString() == true){

        response.sendRedirect("answerTest.jsp");

      }

   %>

   <p id="tomStyle">5秒记住您看到的字符序列:<br>

      <%= testString %>

      <br>5秒后,将转到答题页.

      <% response.setHeader("refresh", "5"); %>

   </p>

</body>

</html>

answerTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<style type="text/css">

   #tomStyle{

      font-family: 宋体;

      font-size: 26;

      color: blue;

   }

</style>

</head>

<jsp:useBean id="memory" class="sea.water.Memory" scope="session" />

<body bgcolor="#ffccff">

   <form action="judgeAnswer.jsp" id="tomStyle" method="post">

      您记住的字符序列是怎样的,请选择:

      <%

        int n = memory.getGrade();

        memory.setIsGivenTestString(false);

        for(int i = 1;i<=n;i++){

           out.print("<br>"+i+"个字符:");

           out.print(

              "<input type=radio id=tomStyle name=R"+ i +" value=''/>"+  

              "<input type=radio id=tomStyle name=R"+ i +" value='●'/>●"+

              "<input type=radio id=tomStyle name=R"+ i +" value='▲'/>▲"+

              "<input type=radio id=tomStyle name=R"+ i +" value='■'/>■"+

              "<input type=radio id=tomStyle name=R"+ i +" value=''/>"

           );

        }

      %>

      <br><input type="submit" id="tomStyle" value="提交" />

      <input type="reset" id="tomStyle" value="重置" />

   </form>

</body>

</html>

judgeAnswer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<jsp:useBean id="memory" class="sea.water.Memory" scope="session" />

<body bgcolor="white">

   <p style="font-family: 宋体;font-size: 26;color: blue;">

      <%

        memory.setIsGivenTestString(false);

        request.setCharacterEncoding("UTF-8");

        int n = memory.getGrade();

        StringBuffer buffer = new StringBuffer();

        for(int i = 1;i <= n;i++){

           buffer.append(request.getParameter("R" + i));

           out.print("" + request.getParameter("R" + i));

        }

        String userAnswer = new String(buffer);

        String testString = memory.getTestString();

        if(testString.equals(userAnswer)){

           out.print("您记忆不错");

        }else{

           out.print("您没记忆住!答案是:<br>"+testString);

        }

      %>

      <br><a href="giveTest.jsp">返回,继续练习记忆</a>

      <br><a href="choiceGrade.jsp">重新选择级别</a>

   </p>

</body>

</html>

效果图

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/570280.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C语言实现简单CRC校验

目录 一、实现题目 二、send模块 三、receive模块 四、运行截图 一、实现题目 二、send模块 #include <stdio.h> #include <string.h>// 执行模2除法&#xff0c;并计算出余数&#xff08;CRC校验码&#xff09; //dividend被除, divisor除数 void divide…

基于STM32的DAC简易信号发生器设计(HAL库)

前言&#xff1a;本文为手把手教学制造 DAC 简易信号发生器的教程&#xff0c;本教程的 MCU 使用 STM32F103ZET6 。以 HAL 库的 DAC 函数作为代码基础进行编程&#xff0c;使得信号发生器可以产生各种类型的信号波&#xff0c;包括&#xff1a;方波、三角波、正弦波和噪声波&am…

kafka部分partition的leader=-1修复方案整理

kafka部分partition的leader-1修复方案整理 1. 背景说明2. 修复测试2.1 创建正常的topic并验证生产和消费2.2 停止kafka模拟leader-12.3 修复parition2.4 修复完成验证生产消费是否恢复 3. 疑问和思考3.1 kafka在进行数据消费时&#xff0c;如果有partition的leader-1&#xff…

新火种AI|Devin再次震撼谷歌!但却是以被质疑造假的方式...

作者&#xff1a;小岩 编辑&#xff1a;彩云 我们常说有人的地方就有江湖&#xff0c;就会存在炒作&#xff0c;扒皮和虚伪。没想到&#xff0c;到了人工智能这里&#xff0c;也是一样。 4月9日&#xff0c;一位自称有35年软件工程师经验的网络博主卡尔逐帧复现了人工智能软…

09—DOM和BOM

一、DOM 1、HTML DOM (文档对象模型) 文档对象模型&#xff08;Document Object Model&#xff0c;DOM&#xff09;是表示和操作HTML和XML文档内容的基础API。当网页被加载时&#xff0c;浏览器会根据DOM模型&#xff0c;将结构化文档&#xff08;比如HTML和XML&#xff09;解…

2024年低碳技术与污染控制技术国际学术会议(ICLCTPCT 2024)

2024年低碳技术与污染控制技术国际学术会议(ICLCTPCT 2024) 2024 International Conference on Low carbon technology and pollution control technology 一、【会议简介】 2024年低碳技术与污染控制技术国际学术会议&#xff0c;是交流科研成果的绝佳平台。 这次会议将汇集世…

Python 高质量类编写指南

原文&#xff1a;https://www.youtube.com/watch?vlX9UQp2NwTk 代码&#xff1a;https://github.com/ArjanCodes/examples/tree/main/2023/classguide Python 高质量类编写指南 我们将通过一些方法增加类的可读性和易用性。 通过&#xff08;按照属性或行为&#xff09;拆分类…

大模型检索召回系统:RAG技术的全面调查与未来展望

随着人工智能技术的飞速发展&#xff0c;大型语言模型&#xff08;LLMs&#xff09;在自然语言处理&#xff08;NLP&#xff09;领域取得了显著成就。然而&#xff0c;这些模型在处理特定领域或知识密集型任务时仍面临挑战&#xff0c;如产生错误信息或“幻觉”。为了克服这些难…

docker-compose搭建redis环境:哨兵模式(一主两重两哨兵)

文章目录 0.BG1. 编写docker-compose.yml文件2. 哨兵配置文件sentinel.conf3.启动容器4.模拟故障转移 0.BG redis环境有多中模式&#xff0c;包括Standalone&#xff0c;Cluster和Sentinel模式等。这里介绍一种简单搭建Sentinel模式的方法&#xff0c;搭建一个一主两重两哨兵的…

做视频号小店一年半,内部玩法曝光,今日全盘托出

大家好&#xff0c;我是电商笨笨熊 腾讯推出电商的消息一出来&#xff0c;就成为了电商界的又一关注点&#xff1b; 不少人称腾讯做电商不会长久&#xff0c;也有人称视频号小店必将成为未来电商黑马&#xff1b; 无论是哪种说法&#xff0c;视频号小店我先替大家做了一年半…

进程状态和优先级(进程第2篇)【Linux复习篇】

目录 一、进程状态 1、进程有什么状态&#xff1f; 2、 Linux下的进程状态有什么&#xff1f; 二、进程优先级 1、进程优先级是什么&#xff1f; 2、为什么要有优先级 3、怎么改进程优先级&#xff1f;要改吗&#xff1f; 4、操作系统如何根据优先级开展调度的&#xff…

使用原型学习和特权信息进行可解释的医学图像分类

Interpretable Medical Image Classification Using Prototype Learning and Privileged Information 摘要 .可解释性通常是医学成像的基本要求。需要先进的深度学习方法来满足这种对可解释性和高性能的需求。 本文研究了训练过程中可用的其他信息是否可用于创建易于理解且强…

DS32K查看内置寄存器数值

需要在debug的时候进行查看&#xff0c;先暂停&#xff0c;再打开EmbSys Registers窗口。 需要先将导出的内容选中并双击&#xff0c;不然复制出来会变成问号。右上角有个复制按钮&#xff0c;复制到剪贴板就行。譬如我这里选择了MCR寄存器&#xff0c;复制出来的就是这个寄存器…

Redis入门到通关之Redis数据结构-List篇

文章目录 ☃️概述☃️数据结构☃️源码☃️其他 欢迎来到 请回答1024 的博客 &#x1f353;&#x1f353;&#x1f353;欢迎来到 请回答1024的博客 关于博主&#xff1a; 我是 请回答1024&#xff0c;一个追求数学与计算的边界、时间与空间的平衡&#xff0c;0与1的延伸的后端…

七分钟“手撕”三大特性<多态>

目录 一、学习多态之前需要的知识储备 二、重写 1.什么是重写 2.重写可以干嘛 3.怎么书写重写 4.重载与重写的区别 三、向上转型 1.什么是向上转型&#xff1f; 2.向上转型的语法 3.向上转型的使用场景 四、多态是什么 六、多态实现 七、多态的好处 八、多态的缺…

程序员过了35岁没人要?“这行越老越香”

程序员35岁失业&#xff1f;参加完OceanBase开发者大会&#xff0c;我又悟了&#xff01; 周六参加了OceanBase2024 开发者大会的现场&#xff0c;来之前我其实挺忐忑的&#xff0c;我觉得一个数据库产品的发布会&#xff0c;能有什么新鲜的东西&#xff1f; 踏入酒店的那一刻&…

经风靡全球的 PHP 为何逐渐失去优势?

TIOBE 编程语言人气指数发布更新&#xff0c;并提出“PHP 的魔力是否正在消散&#xff1f;”的灵魂拷问。今年 4 月&#xff0c;PHP 在 TIOBE 编程语言指数榜上仅位列第 17&#xff0c;“成为其有史以来的最低排位”。 暴露 PHP 人气急剧下滑的还不只是 TIOBE 榜单。在年度 Sta…

MP4转gif如何操作?一个常见方法分享

MP4是一种视频格式&#xff0c;而gif则是图片格式。当我们需要将MP4格式的时候转成gif格式图片的时候要怎么操作呢&#xff1f;怎样在不下载软件的情况下在线转换格式呢&#xff1f;很简单&#xff0c;通过使用gif图片制作&#xff08;https://www.gif.cn/&#xff09;工具-GIF…

Android开发者必备:RootEncoder引领实时流媒体传输革新

Android开发者必备&#xff1a;RootEncoder引领实时流媒体传输革新 I. 引言 A. RootEncoder简介 RootEncoder for Android&#xff08;rtmp-rtsp-stream-client-java&#xff09;是一个功能强大的流编码器&#xff0c;旨在通过多种协议&#xff08;包括RTMP、RTSP、SRT和UDP…

VR全景创业项目应该如何开展?未来有市场吗?

伴随着5G网络的发展&#xff0c;VR全景得到了众多的关注和提升。与此同时&#xff0c;各行各业都开始关注自身产业在互联网的展示效果&#xff0c;因为年轻一代的生活已经离不开互联网&#xff0c;而VR全景在互联网上的3D展示效果能给商家带来流量&#xff0c;提升营业额。 随着…