JSP之登录,注册页面(一)
2015-11-12 22:50
519 查看
摘要:本系列会制作一个简单的需要JSP,servlet,oracle一起完成的登录,注册页面
1,首先需要一个登录的界面login.jsp
代码如下:<%@ page language="java" import="java.util.*" pageEncoding="GBK" contentType="text/html; charset=GBK"%> <% 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>My JSP 'login.jsp' starting page</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="stylesheet" type="text/css" href="styles.css"> --> </head> <script type="text/javascript"> function func(ac) { form=document.getElementById("form1"); form.action=ac; form.submit(); } </script> <body> <form id="form1"> 登录名:<input type="text" name="name"/><br/> 密 码:<input type="password" name="password"/><br/> <input type="button" value="登录" onclick="func('lotry')"/> <input type="button" value="注册" onclick="func('regist.jsp')"> </form> </body> </html>
2,需要一个用来服务登录的servlet LoginEntry.java
package servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import dao.userdata; @WebServlet(urlPatterns={"/lotry"}) public class LoginEntry extends HttpServlet{ userdata dao; HttpSession hs; @Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { req.setCharacterEncoding("GBK"); String name=req.getParameter("name"); String pass=req.getParameter("password"); dao=userdata.getdao(); if(dao.login(name, pass)){ req.getRequestDispatcher("success.jsp").forward(req, res); }else{ req.getRequestDispatcher("failed.jsp").forward(req, res); } } }
3,需要一个登录成功然后跳转的页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK" contentType="text/html; charset=GBK"%> <% 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>My JSP 'success.jsp' starting page</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="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 恭喜你,成功登录 </body> </html>
4,需要一个登录失败的跳转页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK" contentType="text/html; charset=GBK"%> <% 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>My JSP 'failed.jsp' starting page</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="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 登录失败,<a href="login.jsp">请重新登录</a> </body> </html>
相关文章推荐
- 《Head First Servlet JSP》web服务器,容器,servlet的职责
- 解决js中setTimeout()函数的兼容问题
- week10---11月13日 JS基础(五)
- json.stringfy()和json.parse()
- js执行上下文
- JsonCpp Documentation
- JSP页面中的pageEncoding和contentType(charset)两种属性的区别
- jsp中的JSTL与EL表达式用法
- JS中的this
- javascript中的 offsetParent
- JS 实现抽奖
- javascript 中的 true 或 false
- HTML5怎么读取json文件
- Jsoup模拟登陆例子
- JavaScript中With 语句使用方法实例
- JSP之购物车
- 什么是Javascript Hoisting?
- [读书笔记]高性能JS-加载执行
- 2048游戏JS实战笔记1
- Js的两种post方式