jsp 实验16 MVC 表白墙

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

ExpressWish_Bean.java

package web;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
public class ExpressWish_Bean { 
    public HashMap<String,ExpressWish> wishList; 
    ArrayList<ExpressWish> wishes;
    public ExpressWish_Bean(){
        wishList = new HashMap<String,ExpressWish>();
        wishes = new ArrayList<ExpressWish>();
    }
    public void addExpressWish(String id,ExpressWish expressWish){
        wishList.put(id,expressWish);
        putToArrays(wishList);
    }
    public void removeExpressWish(String id){
        wishList.remove(id);
        putToArrays(wishList);
    }
    public String getId(int index) {
       return wishes.get(index).getId();
    }
    public String getPeopleName(int index) {
       return wishes.get(index).getPeopleName();
    }
    public String getTitle(int index){
        return wishes.get(index).getTitle(); 
    }
    public String getContent(int index){
        return wishes.get(index).getContent(); 
    }
    public String getDateTime(int index){
        return wishes.get(index).getDateTime();  
    }
    public int size() {
        return wishes.size();
    }
    void putToArrays(HashMap<String,ExpressWish> list){
        wishes.clear();
        Iterator<ExpressWish> iterator = list.values().iterator();
        while(iterator.hasNext()){
            ExpressWish wish = iterator.next();
            wishes.add(wish); 
        }
    }
}

 

ExpressWish.java

package web;

public class ExpressWish {

String contents;

String title;

String dateTime;

String peopleName;

String id;

public void setId(String id) {

this.id = id;

}

public String getId() {

return id;

}

public void setPeopleName(String s) {

peopleName = s;

}

public String getPeopleName() {

return peopleName;

}

public void setContent(String s) {

contents = s;

}

public String getContent() {

return contents;

}

public void setTitle(String s) {

title = s;

}

public String getTitle() {

return title;

}

public void setDateTime(String s) {

dateTime = s;

}

public String getDateTime() {

return dateTime;

}

}

ExpressWish_Servlet.java

package text;

import web.ExpressWish;

import web.ExpressWish_Bean;

import java.util.*;

import java.io.*;

import java.time.LocalDateTime;

import javax.servlet.*;

import javax.servlet.http.*;

@SuppressWarnings("unused")

public class ExpressWish_Servlet extends HttpServlet{

/**

*

*/

private static final long serialVersionUID = 1L;

int index;

public void init(ServletConfig config) throws ServletException{

super.init(config);

}

synchronized long getIndex() {

index = index+1;

return index;

}

public void service(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{

request.setCharacterEncoding("utf-8");

ExpressWish_Bean wishWallBean = null;

ServletContext application = getServletContext();

wishWallBean = (ExpressWish_Bean)application.getAttribute("wishWallBean");

if(wishWallBean == null ){

wishWallBean = new ExpressWish_Bean();

application.setAttribute("wishWallBean",wishWallBean);

}

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

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

String content = request.getParameter("contents");

ExpressWish wish = new ExpressWish();

if(peopleName.length()==0||title.length()==0||content.length()==0){

response.sendRedirect("example7-2.jsp");

return;

}

wish.setPeopleName(peopleName);

wish.setTitle(title);

wish.setContent(content);

LocalDateTime dateTime = LocalDateTime.now();

String str = dateTime.toString();

String time =str.substring(0,str.lastIndexOf("."));

wish.setDateTime(time);

long number = getIndex();

wish.setId(""+number);

wishWallBean.addExpressWish(""+number,wish);

response.sendRedirect("example7-2-show.jsp");

}

}

example7-2.jsp

<%@ page contentType="text/html" %>

<%@ page pageEncoding = "utf-8" %>

<HTML>

<style>

#tom{

font-family:宋体;font-size:18;color:blue

}

</style>

<body bgcolor = #ffccff>

<form action="handleExpress" id="tom" method="post" >

表白者:<input type="text" id = "tom" name="peopleName" size = 28/>

<br>标题:<input type="text" id = "tom" name="title" size = 30/>

<br>内容:<br>

<textArea name="contents" id = "tom" rows="10" cols=36 >

</textArea>

<br><input type="submit" id="tom" value="提交表白" name="submit"/>

</form>

<p id="tom">

<a href="example7-2-show.jsp">查看表白墙</a>

</p></body></HTML>

example7-2-show.jsp

<%@ page contentType="text/html" %>

<%@ page pageEncoding = "utf-8" %>

<jsp:useBean id="wishWallBean" class ="web.ExpressWish_Bean" scope="application"/>

<style>

#tom{

font-family:宋体;font-size:26;color:blue

}

</style>

<HTML><body bgcolor=white>

<table border=1>

<tr><th id=tom>id</th><th id=tom>表白人</th><th id=tom>标题</th>

<th id=tom>时间</th><th id=tom>表白内容</th>

<% for(int i=0;i<wishWallBean.size();i++){

out.print("<tr>");

out.print("<td id=tom>"+wishWallBean.getId(i)+"</td>");

out.print("<td id=tom>"+wishWallBean.getPeopleName(i)+"</td>");

out.print("<td id=tom>"+wishWallBean.getTitle(i)+"</td>");

out.print("<td id=tom>"+wishWallBean.getDateTime(i)+"</td>");

out.print("<td ><textArea rows=5 cols=20 id=tom>"+wishWallBean.getContent(i)+

"</textArea></td>");

out.print("</tr>");

}

%> </table>

<a id =tom href="example7-2.jsp ">去表白</a>

</body></HTML>

example7-2-delete.jsp

<%@ page contentType="text/html" %>

<%@ page pageEncoding = "utf-8" %>

<jsp:useBean id="wishWallBean" class ="web.ExpressWish_Bean" scope="application"/>

<HTML><body bgcolor = pink>

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

管理员删除表白的页面。

<form action="" method=post >

输入密码:<input type="password" name="password" size=12 /><br>

输入表白id:<input type="text" name="peopleId" size=6 />

<br><input type="submit" name="submit" value="删除"/>

</form>

<% request.setCharacterEncoding("utf-8");

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

String id=request.getParameter("peopleId");

if(password == null ) password = "";

if(id == null ) id = "";

if(password.equals("123456")){

wishWallBean.removeExpressWish(id);

}

%>

<a href="example7-2-show.jsp">查看表白墙</a>

</p></body></HTML>

web.xml

<?xml version="1.0" encoding="utf-8"?>

<web-app>

    <!--  以下是web.xml文件新添加的内容 -->

  

    <servlet>

        <servlet-name>handleExpress</servlet-name>

        <servlet-class>web.ExpressWish_Servlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>handleExpress</servlet-name>

        <url-pattern>/handleExpress</url-pattern>

    </servlet-mapping>

   

</web-app>

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

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

相关文章

#内部类#

1,概念 如果一个类定义在另一个类的内部&#xff0c;这个内部类就叫做内部类。内部类是一个独立的类&#xff0c;它不属于外 部类&#xff0c;更不能通过外部类的对象去访问内部类的成员。外部类对内部类没有任何优越的访问权限。重点&#xff1a;内部类是一个独立的类 注意&…

JavaEE 多线程详细讲解(2)

1.线程不安全分析 &#xff08;1&#xff09;线程不安全的主要原因就是&#xff0c;系统的抢占式执行&#xff0c;对于内核设计者来说&#xff0c;这是非常方便的一个执行方式&#xff0c;但是这却却导致线程不安全的问题&#xff0c;也有不抢占执行的系统&#xff0c;但是这种…

从心理学角度看,GPT 对人有什么影响?

开启个性化AI体验&#xff1a;深入了解GPT的无限可能 导言 GPT 与我们日常生活的融合标志着技术进步的重大飞跃&#xff0c;为提高效率和创新提供了前所未有的机遇。然而&#xff0c;当我们与这些智能系统日益紧密地交织在一起时&#xff0c;探索它们对个人产生的细微的心理影响…

15-LINUX--线程的创建与同步

一.线程 1.线程的概念 线程是进程内部的一条执行序列或执行路径&#xff0c;一个进程可以包含多条线程。 2.线程的三种实现方式 ◼ 内核级线程&#xff1a;由内核创建&#xff0c;创建开销大&#xff0c;内核能感知到线程的存在 ◼ 用户级线程&#xff1a;线程的创建有用户空…

抖音APP运用的AI技术拆解

1.推荐系统&#xff08;RS&#xff09; 用户画像&#xff1a;根据用户的信息&#xff08;如地区、性别、年龄、收藏、关注......&#xff09;进行分析&#xff0c;构建用户画像&#xff0c;对用户进行分类&#xff1b; 行为分析&#xff1a;将用户的显形行为数据&#xff08;如…

PaddleOCR使用

最近在项目过程中需要用到文字识别的能力&#xff0c;之前没有接触过。需要对现有的开源能力进行调研和学习。 1. 基本概念 1.1 PaddlePaddle PaddlePaddle 是一个由百度开源&#xff0c;基于 Python 的深度学习框架。PaddlePaddle 针对不同的硬件环境提供了不同的安装包或安…

2024/5/9 QTday4

完成定时器制作 #include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this);connect(&timer2, &QTimer::timeout, this, &Widget::label_begin);connect(&…

Linux0.11中MINIX 文件系统

阅读linux 的源码的时候对minix 文件系统有很多的疑惑&#xff0c;根据自己的认识将这些做一个总结。 MINIX 文件系统由六个部分组成&#xff0c;分别是引导块&#xff0c;超级块&#xff0c;i结点位图&#xff0c;逻辑块位图&#xff0c;i结点&#xff0c;数据块。 引导块&am…

Python 中 “yield“ 的不同行为

在我们使用Python编译过程中&#xff0c;yield 关键字用于定义生成器函数&#xff0c;它的作用是将函数变成一个生成器&#xff0c;可以迭代产生值。yield 的行为在不同的情况下会有不同的效果和用途。 1、问题背景 在 Python 中&#xff0c;“yield” 是一种生成器&#xff0…

【Pytorch】1.读取训练数据集

导入Dataset类 from torch.utils.data import Dataset # 注意是Dataset&#xff08;大写&#xff09;的才是类通过jupyter我们可以阅读一下Dataset类的具体使用方法 help(Dataset) # 或者直接 Dataset??我们可以看到具体对Dataset类的解释 从蓝色字体我们可以得出 所有的代…

鸿蒙开发-ArkTS语言-容器-非线性容器

鸿蒙开发-UI-web 鸿蒙开发-UI-web-页面 鸿蒙开发-ArkTS语言-基础类库 鸿蒙开发-ArkTS语言-并发 鸿蒙开发-ArkTS语言-并发-案例 鸿蒙开发-ArkTS语言-容器 文章目录 前言 一、非线性容器 1.HashMap 2.HashSet 3.TreeMap 4.TreeSet 5.LightWeightMap 6.LightWeightSet 7.P…

vue uniapp 小程序 判断日期是今天(显示时分秒)、昨天、本周的周几、超出本周显示年月日

效果图&#xff1a; util.js /*** 转换时间*/ const messageFormat (datetime) >{ let result "";let currentTime new Date();if(isToday(datetime)){result datetime.substring(11,16);}else if(isYesterday(datetime)){result "昨天";}else if(…

EasyExcel导出带自定义下拉框数据的Excel模板

文章目录 前言&#x1f4dd;一、导入依赖二、创建导出工具1.创建模板实体类2.创建自定义注解3.添加动态选择接口4.EasyExcelUtil工具类 三、导出、导入Excel接口1.导出接口2.导入接口3.导出结果 总结 前言&#x1f4dd; 在项目中导入excel时需要通过下拉框选择值传入&#xff…

解决在Outlook中预定Teams会议不显示入会链接的问题

今天遇到一个很蛋疼的teams问题&#xff0c;花了点时间才解决。本来以为是很简单的问题&#xff0c;随便网上冲浪一下就能找到答案的&#xff0c;结果根本就没有好的解决方案&#xff0c;所以我分享出来希望后来的老哥少走点弯路。 问题描述 简单来说&#xff0c;就是在Outlo…

Pytorch入门—Tensors张量的学习

Tensors张量的学习 张量是一种特殊的数据结构&#xff0c;与数组和矩阵非常相似。在PyTorch中&#xff0c;我们使用张量来编码模型的输入和输出&#xff0c;以及模型的参数。 张量类似于NumPy的ndarrays&#xff0c;只是张量可以在GPU或其他硬件加速器上运行。事实上&#xf…

IntelliJ IDEA 配置JDK

IntelliJ IDEA-之配置JDK 我们的开发神器IDEA安装好了之后&#xff0c;在实际开发中&#xff0c;我们如何去配置好JDK的版本呢&#xff1f; 注意&#xff1a;需要保证JDK在已经成功安装的情况下&#xff0c;再进行IDEA的配置 现在就行动&#xff0c;让IntelliJ IDEA成为你征…

Windows系统使用powershell批量移动特定起始位置的“快捷方式”

移动特定起始位置的“快捷方式” 快捷方式都对应一个的目标和“起始位置”&#xff0c;现在想要把特定起始位置的快捷方式移动到一个文件夹中。 新建文本文档&#xff0c;输入如下内容&#xff1a; # 设置变量 $oldPath "D:\111\111_1" $newPath "D:\111\1…

C语言—操作符详解(操作符、进制转换、原码反码补码、结构体)

1.操作符分类 算术操作符&#xff1a; 、- 、 * 、 / 、%移位操作符&#xff1a;<< >> //移动的是二进制位位操作符&#xff1a;& | ^ //使用二进制位进行计算赋值操作符&#…

前端js面试题--从字符串中删除删除注释代码

问题&#xff1a;从字符串中删除删除注释代码 描述&#xff1a; solution(weex,rex # and react\nflutter\nnative ssss !hybrid app, [#, !]) 写一个solution函数清除后面参数数组里面的字符串 打印效果 代码1 思路&#xff1a; 将字符全凡是有去掉标志符号的全部添加\n…

Ubuntu20.4中复现Graspness

Ubuntu20.4中复现Graspness 文章目录 Ubuntu20.4中复现Graspness1.安装cuda和cudnn2.安装pytorch3.安装MinkowskiEngine4.编译graspnetAPI5. RuntimeError: "floor" "_vml_cpu" not implemented for IntRefernece &#x1f680;非常重要的环境配置&#x1…
最新文章