jsp杂记
2016-09-04 11:36
323 查看
1.out.print和<%= %>的区别
out.print(““);
String alter=”验证码不正确”;<%=alter %>
2.jsp跨页面验证并返回上级页面弹出提示,注释部分重点
上级页面代码
userInfo代码
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>
相关文章推荐
- jsp页面杂记
- jsp杂记
- jsp杂记
- jsp 杂记
- 杂记(三):jsp添加登录验证码
- jsp学习杂记
- Java Web开发——JSP基本语法杂记
- Struts,MVC 的一种开放源码实现用这种servlet和JSP框架管理复杂的大型网站
- 浅析jsp中usebean的作用域
- jsp中利用cos进行web文件上传
- 如何实现JSTL if else if else 的jsp标签
- 在JSP中使用Spring
- JSP连接MySQL数据库
- 【JSP】Cookie的使用及保存中文,并用Cookie实现购物车功能
- 解决Myeclipse中导入自定义的配色方案后,JSP中的js代码块为白色背景的问题
- JSP方便路径
- jsp(Java Server Pages)和js(JavaScript)的区别:
- 在JSP页面验证邮箱
- jsp--javabeans
- Servlet与JSP的区别