当前位置: 首页 > news >正文

javaEE7

1.

<%@ page pageEncoding="UTF-8"%><%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <%@ page import="java.math.*"%> <html> <head><title>网站计数器</title></head> <body> <%! BigInteger count = null ;  //定义一个%> <%! public BigInteger load(File file){ BigInteger count = null ;  // 接收数据 try{  //判断是否有存储数据的文件if(file.exists()){ Scanner scan = new Scanner(new FileInputStream(file)) ;if(scan.hasNext()){ count = new BigInteger(scan.next()) ;//将内容放到BigInteger类中} scan.close() ; } else {   count = new BigInteger("0") ;  // 从0开始save(file,count) ;   // 保存为一个新的文件} }catch(Exception e){ e.printStackTrace() ; } return count ; } public void save(File file,BigInteger count){  //保存计数文件try{ PrintStream ps = null ;ps = new PrintStream(new FileOutputStream(file)) ;ps.println(count) ;ps.close() ; }catch(Exception e){ e.printStackTrace() ; } } %> <% String fileName = this.getServletContext().getRealPath("/") + "count.txt";  // 保存所有的计数结果 File file = new File(fileName) ; if(session.isNew()){  //同一次会话不重复计数synchronized(this){ count = load(file) ;   count = count.add(new BigInteger("1")) ;    // 再原本的基础上增加1。 save(file,count) ; } } %> <h2>您是第<%=count==null?0:count%>位访客!</h2> </body> </html>  

2.

<%@ page language="java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><%String username = "";String password = "";// 获取cookieCookie[] cookies = request.getCookies();// 如果为空,则停留在该页面if(cookies == null){return ;// 不为空则获取用户名和密码}else{for(int i = 0; i < cookies.length; i++){if("username".equals(cookies[i].getName())){username = cookies[i].getValue();}if("password".equals(cookies[i].getName())){password = cookies[i].getValue();}}// 验证用户名和密码if("admin".equals(username) && "123".equals(password)){session.setAttribute("username", username);session.setAttribute("password", password);}}%><form action="test" method="post">用户名:<input type="text" name="username"/><br/>密&nbsp;&nbsp;&nbsp;码:<input type="password" name="password" /><br /><input type="submit" value="登陆" /></form></body></html>

3.

Index.jsp

<%@ page  pageEncoding="utf-8"%><html><body><iframe src="content.jsp" name="content" width="100%" height="80%"></iframe><form action="addinfo.jsp" target="content" id="chatform" method="post">昵称:<input type="text" name="nicheng" id="nicheng">发言:<input type="text" name="info" id="info"><input type="button" value="确定" onclick="check()"></form><script>function check(){var nicheng=document.getElementById("nicheng").value;var info=document.getElementById("info").value;if(nicheng==''||info==''){alert("昵称或留言内容不能为空");}else{document.getElementById("chatform").submit();}}</script></body></html>

Content.jsp

<%@ page pageEncoding="utf-8" import="java.util.*"%><%@ page import="org.apache.commons.lang3.StringUtils"%><html><head>  <meta http-equiv="refresh" content="10"><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">   </head><body><%request.setCharacterEncoding("UTF-8");%><%=application.getAttribute("infoList1")    %></body></html>

Addinfo.jsp

<%@ page pageEncoding="utf-8" import="java.util.*,java.text.*"%><%@ page import="org.apache.commons.lang3.StringUtils"%><html><body><%request.setCharacterEncoding("UTF-8");String nicheng=request.getParameter("nicheng");String info=request.getParameter("info");String time=new SimpleDateFormat("yy-MM-dd kk:mm:ss").format(new Date());//当前时间List<String> infoList=new ArrayList<String>();String s=(String)application.getAttribute("infoList1");if(s==null){//第一次存储信息s="";}else{String[] a=s.split("<br>");int b=a.length;if(b==30){//够30条s="";}infoList.add(nicheng+"在"+time+"说:"+info+"<br>");s=s+StringUtils.strip(infoList.toString(),"[]");//添加}application.setAttribute("infoList1", s);response.sendRedirect("content.jsp");//重定向到content.jsp%></body></html>

GetNumer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="UTF-8"></head><body>程序随机产生了一个0-100间的整数,请猜一猜<br><%int n=(int)(Math.random()*100)+1;session.setAttribute("save", new Integer(n));%><form action="caishu.jsp" method="post"><input type="text" name="t1"/><input type="submit" value="guess"/></form></body></html>

Caishu.jsp

<%@ page pageEncoding="UTF-8" %><html><body><body>程序随机产生了一个0-100间的整数,请猜一猜<br><form  action="caishu.jsp" method="get"><input type="text" name="t1"/><input type="submit" value="guess"/></form><%String t1=request.getParameter("t1");Integer integer=(Integer)session.getAttribute("save");int realnumber=integer.intValue();if(t1!=null){int t=Integer.parseInt(t1);if(t==realnumber){out.print("right,<a href='getNumber.jsp'>再来一次</a>");}else if(t<realnumber){out.print("too small");out.println(realnumber);}else{out.print("too large");out.println(realnumber);}}%></body></html>

http://www.lryc.cn/news/319051.html

相关文章:

  • int与integer的区别
  • Golang实现Redis分布式锁(Lua脚本+可重入+自动续期)
  • 音乐播放器-C#实现
  • 如何本地搭建hMailServer邮件服务
  • 裸机编程的几种模式、架构与缺陷。
  • TSINGSEE青犀视频AI方案:数据+算力+算法,人工智能的三大基石
  • Linux认识与学习BASH
  • Python JSON 序列化以及反序列化 文件读写
  • Spring MVC 返回JSON数据
  • 前端基础——HTML傻瓜式入门(1)
  • 【AI】如何创建自己的自定义ChatGPT
  • 电子科技大学链时代工作室招新题C语言部分---题号E
  • K8S CNI
  • Python数据分析实验一:Python数据采集与存储
  • 丘一丘正则表达式
  • 工业物联网平台在水务环保、暖通制冷、电力能源等行业的应用
  • 【研发日记】Matlab/Simulink技能解锁(二)——在Matlab Function编辑窗口Debug
  • 从键盘输入两个数,求它们的和并输出 从键盘输入三个数到a,b,c中,按公式值输出
  • 密码解密 C卷(100%用例)(JavaPythonC++Node.jsC语言)
  • 因为manifest.json文件引起的 android-chrome-192x192.png 404 (Not Found)
  • 『 Linux 』进程替换( Process replacement ) 及 简单Shell的实现(万字)
  • 【Linux】从零开始认识进程 — 前篇
  • 公众号留言功能恢复了,你的开通了吗?
  • C语言葵花宝典之——文件操作
  • SSM框架,MyBatis-Plus的学习(下)
  • 边缘计算网关的工作原理及其在工业领域的应用价值-天拓四方
  • 下载指定版本的pytorch
  • STL:List从0到1
  • 利用高分五号02星高光谱数据进行地物识别
  • 前端如何识别上传的二维码---jsQR