jsp杂记
来源:互联网 发布:什么软件商城最好用 编辑:程序博客网 时间:2024/05/17 02:38
1.out.print和<%= %>的区别
out.print(““);
String alter=”验证码不正确”;<%=alter %>
2.jsp跨页面验证并返回上级页面弹出提示,注释部分重点
上级页面代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>注册</title><style type="text/css">#hand{ text-align:center; font-weight:bold;}#form1{ text-align: center;}#div1{ margin-top:30px; }#div2{ margin-top:30px; }#div3{ margin-top:20px; }#div4{ margin-top:20px; }input[type="submit"]{ width:120px; height:30px; background-color:#09C; margin-left:50px; }#userName{ width:250px; height:30px; }#code{ height:30px; }input[type="password"]{ width:250px; height:30px; }</style><%--本页面验证提示 --%><script type="text/javascript"> function checkUserInfo(){ var userName=document.getElementById("userName").value; var pwd=document.getElementById("pwd").value; var codes=document.getElementById("codes").value; if(userName.length<=0 ||pwd.length<=0 || codes.length<=0){ alert("请输入完整信息") return false; } else{ return true; } }</script></head><body><% //接收下级页面UserInfo返回过来的状态码status,用UserInfo页面status的值来判断本页面弹出的提示 String status=request.getParameter("status"); if(status!="" && status!=null){ if(status.equals("0")){ out.print("<script type='text/javascript'>alert('验证码不正确!');</script>"); } if(status.equals("1")){ out.print("<script type='text/javascript'>alert('用户名或密码错误!');</script>"); } }%><div id="hand">请 输 入 注 册 信 息</div><!--post请求方式--> <form id="form1" method="post" action="UserInfo.jsp" onsubmit="return checkUserInfo()"> <div id="div1">用户名:<input type="text" name="userName" id="userName"></div> <div id="div2"> 密 码:<input type="password" name="pwd" id="pwd"></div> <div id="div3">验证码 <img border=0 src="image.jsp" id="imgRandom" onclick="this.src='image.jsp?abc='+Math.random()"> <input type="text" id="codes" name="codes"> </div> <div id="div4"><input type="submit" value="确定" name="confirm"></div> </form> <% session.setAttribute("name", "admin"); session.setAttribute("pwd", "123456");%></body></html>
userInfo代码
<%@page import="javafx.scene.control.Alert"%><%@page import="javax.swing.JOptionPane"%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><% String userName=request.getParameter("userName"); String pwd=request.getParameter("pwd"); String code=request.getParameter("codes"); String codeSessin=session.getAttribute("code").toString(); if(userName.equals("admin") && pwd.equals("123456")) { if( codeSessin.equals(code)){ response.sendRedirect("MainPage.jsp"); } else{ //这自定义状态码status,传到regis以用来辨识弹出状态 response.sendRedirect("Register.jsp?status=0"); } } else{ response.sendRedirect("Register.jsp?status=1"); }%></body></html>
0 0
- jsp 杂记
- jsp杂记
- jsp杂记
- jsp学习杂记
- jsp页面杂记
- java,jsp,的数据库日期操作杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- 杂记
- ln命令
- LeetCode 122 Best Time to Buy and Sell Stock II (贪心)
- C#读取文件内容,包括ArrayList使用和类型转换
- bootmode -- TI DSP
- 单例模式总结
- jsp杂记
- error:This function or variable may be unsafe
- h5学习笔记:Table2
- 记忆化搜索
- UNIX网络编程笔记 第三章 套接字编程简介
- C#实现窗口抖动
- project euler 107
- 渗透之探针篇
- GDT 与 LDT