玫瑰花Java web程序

2024-05-12 14:32
文章标签 java 程序 web 玫瑰花

本文主要是介绍玫瑰花Java web程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

玫瑰花Java web程序

  有兴趣的同学可以参考一下

Java类RoseController

package com.spring.controller;import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;import javax.print.attribute.HashAttributeSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import net.sf.json.JSONObject;import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;@Controller
public class RoseController {//鐢ㄤ簬璺宠浆椤甸潰@RequestMapping(value="skip/page",method = {RequestMethod.GET,RequestMethod.POST})public ModelAndView skipRose(HttpServletRequest request,HttpServletResponse response){ModelAndView mav=new ModelAndView();System.out.println("come in system");mav.addObject("wishing", "YOU ARE WELCOME!");mav.setViewName("rose/roseindex");return mav;}///灏嗘暟鎹繚瀛樺埌鏂囨湰涓�@RequestMapping(value="save/keepdata",method = {RequestMethod.GET,RequestMethod.POST})public ModelAndView keepdata(HttpServletRequest request,HttpServletResponse response) throws IOException{request.setCharacterEncoding("UTF-8");//response.setContentType("text/html,charset=UTF-8");response.setCharacterEncoding("utf-8");PrintWriter out=response.getWriter();ModelAndView mav=new ModelAndView();String keyword=request.getParameter("pwd");File file=new File("D:\\xuan22.txt");if(!file.exists()){file.createNewFile();}/*PrintStream p = new PrintStream(new BufferedOutputStream(new FileOutputStream(aFile, true)));杩欓噷鐨則rue璇存槑鏄拷鍔�濡傛灉false璇存槑瑕嗙洊*/FileOutputStream fos=new FileOutputStream(file,true);///保存文件续写OutputStreamWriter osw=new OutputStreamWriter(fos);BufferedWriter bufw=new BufferedWriter(osw);//绠�啓//BufferedWriter bufw2=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));Date date=new Date();SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");String time=sdf.format(date);System.out.println("====="+keyword);///鑾峰彇IPString ip="";if (request.getHeader("x-forwarded-for") == null) {  ip=request.getRemoteAddr();//System.out.println("======ip1======="+ip);}else{ip=request.getHeader("x-forwarded-for");//System.out.println("======ip2======="+ip);}//System.out.println("淇濆瓨鏂囦欢");bufw.write(keyword+"======"+ip+"======"+time);bufw.newLine();//bufw.flush();bufw.close();//Map<String,Object> map=new HashedMap();int count=0;HttpSession session=request.getSession();if(request.getParameter("count")!=null){//System.out.println("====3====="+count);count=Integer.parseInt(request.getParameter("count"));}JSONObject json=new JSONObject();if(count<3){count++;json.put("count", String.valueOf(count));json.put("text", "密码不正确。请重新输入!0_0");out.print(json.toString());}else if(count>=3 && count<=6){//System.out.println("===1==="+count);count++;json.put("count", String.valueOf(count));json.put("text", "你怎么那么笨,这么简单的密码都猜不到0_0");out.print(json.toString());}else if(count>=6 && count<=12){//System.out.println("====2=="+count);count++;json.put("count", String.valueOf(count));json.put("text", "惊喜就在这一刻");out.print(json.toString());}else if(count>=12){//System.out.println("====3=="+count);count=0;json.put("count", String.valueOf(count));json.put("text", "想看到惊喜的,请继续输入密码吧");out.print(json.toString());}if(keyword.equals("lovelili201314")){mav.setViewName("rose/roseopen");json.put("text", "密码正确");return mav;}else{mav.addObject("data", "请重新输入!");return null;}}//鐢ㄤ簬璺宠浆椤甸潰@RequestMapping(value="/rose/redirect")public ModelAndView redirectRose(HttpServletRequest request,HttpServletResponse response){ModelAndView mav=new ModelAndView();mav.addObject("wishing", "YOU ARE WELCOME!");mav.setViewName("rose/roseopen");return mav;}}

jsp页面:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>Rose Love from this moment</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><link rel="shortcut icon" href="<%=path%>/images/ico/15.png" type="image/x-icon" /><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script><script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script><style type="text/css">
.inputKey{float:right;margin-right:10px;margin-top:10px;border:2px solid #009;
}.inputKey .input{float:left;height:26px;line-height:26px;font-size:14px;border:0px solid #F60;
}
.inputKey .button{float:left;width:60px;height:26px;line-height:20px;text-align:center; background:#009;color:#fff;font-size:14px;border:0;
}.inputKey .button:hover{float:left;width:60px;height:26px;line-height:20px;text-align:center; background:#001;color:#fff;font-size:14px;border:0;
}#content{width:300px;height:60px;margin:auto;/* margin-top:400px; */
}#imgico{width:300px;height:300px;margin:auto;margin-top:100px;
}
#imgico .img1 {float:left;width:120px;height:300px;/* background-attachment: fixed; */background-image: url(<%=path%>/images/roseimg/14.png);background-repeat: no-repeat;background-position: 0 160;
}
#imgico .img2 {float:right;width:150px;height:300px;/* background-attachment: fixed; */background-image: url(<%=path%>/images/roseimg/2.png);background-repeat: no-repeat;background-position: 0 90;
}
.cuetext{float:left;border:0px solid #F60;margin-top:270px;color:red;font-size:20px;
}
#prompt{width:300px;height:40px;margin:auto;margin-top:0px;
}
#prompttext{height:40px;margin:auto;margin-top:0px;text-align:center;
}</style></head><body><div id="imgico"><div class="img1"></div><div class="img2"><p class="cuetext">亲,请输入密码!</p></div></div><div id="content"> <div class="inputKey"><form action="#" method="post" name="form1"><input type="password" name="keyword" id="keyword" class="input" size="30px"/><input type="button" id="bt1" value="惊喜" class="button" /></form></div></div><div id="prompt"><input type="hidden" id="count" name="count" value="0"/><p id="prompttext" style="color:red"></p></div></body>
</html><script type="text/javascript">
<!--$("#bt1").click(function(){var va=$("#keyword").val();if(va==""){$("#prompttext").text("密码不能为空,请输入!");}else{$.post("save/keepdata",{pwd:$("#keyword").val(),count:$("#count").val()},function(data,textStatus){var jsonObj=eval("("+data+")");$("#count").val(jsonObj.count);$("#prompttext").text(jsonObj.text);});}});$("#keyword").focus(function(){$("#prompttext").text("");$("#keyword").val("");});//-->
</script>

效果图:


弹出玫瑰花效果:



这篇关于玫瑰花Java web程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/982880

相关文章

Java中Map的五种遍历方式实现与对比

《Java中Map的五种遍历方式实现与对比》其实Map遍历藏着多种玩法,有的优雅简洁,有的性能拉满,今天咱们盘一盘这些进阶偏基础的遍历方式,告别重复又臃肿的代码,感兴趣的小伙伴可以了解下... 目录一、先搞懂:Map遍历的核心目标二、几种遍历方式的对比1. 传统EntrySet遍历(最通用)2. Lambd

Django调用外部Python程序的完整项目实战

《Django调用外部Python程序的完整项目实战》Django是一个强大的PythonWeb框架,它的设计理念简洁优雅,:本文主要介绍Django调用外部Python程序的完整项目实战,文中通... 目录一、为什么 Django 需要调用外部 python 程序二、三种常见的调用方式方式 1:直接 im

Spring Boot 中 RestTemplate 的核心用法指南

《SpringBoot中RestTemplate的核心用法指南》本文详细介绍了RestTemplate的使用,包括基础用法、进阶配置技巧、实战案例以及最佳实践建议,通过一个腾讯地图路线规划的案... 目录一、环境准备二、基础用法全解析1. GET 请求的三种姿势2. POST 请求深度实践三、进阶配置技巧1

springboot+redis实现订单过期(超时取消)功能的方法详解

《springboot+redis实现订单过期(超时取消)功能的方法详解》在SpringBoot中使用Redis实现订单过期(超时取消)功能,有多种成熟方案,本文为大家整理了几个详细方法,文中的示例代... 目录一、Redis键过期回调方案(推荐)1. 配置Redis监听器2. 监听键过期事件3. Redi

Spring Boot 处理带文件表单的方式汇总

《SpringBoot处理带文件表单的方式汇总》本文详细介绍了六种处理文件上传的方式,包括@RequestParam、@RequestPart、@ModelAttribute、@ModelAttr... 目录方式 1:@RequestParam接收文件后端代码前端代码特点方式 2:@RequestPart接

SpringBoot整合Zuul全过程

《SpringBoot整合Zuul全过程》Zuul网关是微服务架构中的重要组件,具备统一入口、鉴权校验、动态路由等功能,它通过配置文件进行灵活的路由和过滤器设置,支持Hystrix进行容错处理,还提供... 目录Zuul网关的作用Zuul网关的应用1、网关访问方式2、网关依赖注入3、网关启动器4、网关全局变

SpringBoot全局异常拦截与自定义错误页面实现过程解读

《SpringBoot全局异常拦截与自定义错误页面实现过程解读》本文介绍了SpringBoot中全局异常拦截与自定义错误页面的实现方法,包括异常的分类、SpringBoot默认异常处理机制、全局异常拦... 目录一、引言二、Spring Boot异常处理基础2.1 异常的分类2.2 Spring Boot默

基于SpringBoot实现分布式锁的三种方法

《基于SpringBoot实现分布式锁的三种方法》这篇文章主要为大家详细介绍了基于SpringBoot实现分布式锁的三种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、基于Redis原生命令实现分布式锁1. 基础版Redis分布式锁2. 可重入锁实现二、使用Redisso

SpringBoot的全局异常拦截实践过程

《SpringBoot的全局异常拦截实践过程》SpringBoot中使用@ControllerAdvice和@ExceptionHandler实现全局异常拦截,@RestControllerAdvic... 目录@RestControllerAdvice@ResponseStatus(...)@Except

Springboot配置文件相关语法及读取方式详解

《Springboot配置文件相关语法及读取方式详解》本文主要介绍了SpringBoot中的两种配置文件形式,即.properties文件和.yml/.yaml文件,详细讲解了这两种文件的语法和读取方... 目录配置文件的形式语法1、key-value形式2、数组形式读取方式1、通过@value注解2、通过