jsp实现的简单登陆代码

合集下载

JSP注册页面代码

JSP注册页面代码
</label>
</p>
<p>真实姓名
<label>
<input type="text" name="textfield4" />
</label>
</p>
<p>年龄
<label>
<input type="text" name="textfield5" />
</label>
</p>
<p>职业
<label>
<!--DWLayoutTable-->
<tr>
<td width="528" height="368">&nbsp;</td>
<td width="344" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
</label>
<label>
<input type="submit" name="Submit3" value="返回" />
</label>
</p>
</form> </td>
</tr>

JSP Ajax 用户登录

JSP Ajax  用户登录

JSP Ajax 用户登录
使用Ajax技术来实现用户登录,将会提交登录区域数据。

练习使用这种方法来实现用户登录校验。

(1)创建客户端程序,通过有参数请求把客户的用户名和密码发送到服务器,然后根据服务器返回的结果来判断是否登录成功。

其中发送有参数请求的JavaScri
(3)实现页面的登录界面,注意一些标签的id属性的设置不能有错,不然将
(4)实现服务器处理——check.java文件,它是一个Servlet,主要功能是起到一个控制器作用,将调用逻辑处理模块(一个JavaBean)SqlCheck来判断用户是否
(5)实现逻辑处理模块——SqlCheck.java,它是一个JavaBean,主要功能是查
(6)编译并部署各文件,运行效果如图9-15所示:
图9-15 登录成功。

(完整版)JSP登陆页面代码

(完整版)JSP登陆页面代码
response.sendRedirect("login.htm");
}
%>
如果输入信息有误,则回到登录页面,重新输入登录信息。
注册页面:reg.jsp
请输入您的注册信息:
<table>
<form action="/user/Reg" method="post" name="regform" onsubmit="return regconfirm();">
session.setAttribute("login","ok");
session.setMaxInactiveInterval(-1);
%>
<jsp:forward page="main.jsp"/>
<%
}else{
out.println("用户名或密码输入错误!");
}
%>
如果登录成功,则设定login的值为ok,提交到下一步验证页面,则进入main.jsp页面,否则,如果输入的用户名和密码不合法就打印错误信息,main.jsp页面代码如下:
<tr><td>密码:</td><td><input type="password" name="user_pwd" id="user_pwd" size="20" maxlength=10 onBlur="checkPWD();">*可以包含字母数字(区分大小写),6-10位</td>

使用JSP实现简单的用户登录注册页面示例代码解析

使用JSP实现简单的用户登录注册页面示例代码解析

使⽤JSP实现简单的⽤户登录注册页⾯⽰例代码解析实验要求:将实验2中的系统⽤户登录和注册页⾯改为JSP页⾯,并部署⾃⼰的Web应⽤于Tomcat服务器中具体要求:完成登录JSP页⾯设计和注册页⾯设计在登录页⾯表单中使⽤request对象获取⽤户信息,建⽴新的JSP页⾯完成登录验证(⽤户名和密码⾃⼰指定即可)。

验证结果显⽰(如登录成功/⽤户名密码错误,可以使⽤JavaScript,也可以使⽤新的JSP页⾯)。

在注册页⾯表单中使⽤request对象获取⽤户注册信息(注册项⽬由⾃⼰指定),在新的JSP页⾯显⽰⽤户注册信息,并提⽰注册成功。

代码登录页⾯index.html<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>jsp作业</title><link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet"></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作业</a></div><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav navbar-right"><li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登录</a></li></ul></div></div></nav><div class="container"><div class="jumbotron"><h1>Hello, world!</h1><p>这是⼀个jsp作业</p></div></div></body></html>登录页⾯login.jsp<%@ page contentType="text/html; charset=utf-8" language="java"%><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>登录</title><link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet"></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作业</a></div><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav navbar-right"><li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登录</a></li></ul></div></div></nav><div class="container"><div class="row"><div class="col-md-4"></div><div class="col-md-4"><form class="form-signin" method="post" action="login-check.jsp"><h2 class="form-signin-heading">登录到jsp作业</h2><label for="">⽤户名</label><input type="text" name="username" id="username" class="form-control" placeholder="请输⼊⽤户名" required autofocus><br><label for="">密码</label><input type="password" name="password" id="password" class="form-control" placeholder="请输⼊密码" required><div class="checkbox"><label><input type="checkbox" value="remember-me" checked="checked"> 记住密码</label></div><button type="submit" class="btn btn-primary" id="btn-login">登录</button><a href="reg.jsp" rel="external nofollow" rel="external nofollow" class="btn btn-default">注册</a></form></div><div class="col-md-4"></div></div></body></html>登录结果页⾯login-check.jsp<%@ page contentType="text/html; charset=utf-8" language="java"%><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>登录</title><link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet"></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作业</a><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav navbar-right"><li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登录</a></li></ul></div></div></nav><div class="container"><div class="row"><div class="col-md-4"></div><div class="col-md-4"><form class="form-signin" method="post" action="login-check.jsp"><h2 class="form-signin-heading">登录到jsp作业</h2><label for="">⽤户名</label><input type="text" name="username" id="username" class="form-control" placeholder="请输⼊⽤户名" required autofocus><br><label for="">密码</label><input type="password" name="password" id="password" class="form-control" placeholder="请输⼊密码" required><div class="checkbox"><label><input type="checkbox" value="remember-me" checked="checked"> 记住密码</label></div><button type="submit" class="btn btn-primary" id="btn-login">登录</button><a href="reg.jsp" rel="external nofollow" rel="external nofollow" class="btn btn-default">注册</a></form></div><div class="col-md-4"></div></div></body></html>注册页⾯reg.jsp<%@ page contentType="text/html; charset=utf-8" language="java"%><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>注册</title><link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet"></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作业</a></div><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav navbar-right"><li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登录</a></li></ul></div></div></nav><div class="container"><div class="row"><div class="col-md-4"></div><div class="col-md-4"><form class="form-signin" action="reg-submit.jsp" method="post"><h2 class="form-signin-heading">注册到jsp作业</h2><div id="info"></div><label for="">⽤户名</label><input type="text" name="username" id="username" class="form-control" placeholder="请输⼊⽤户名" required autofocus><br><label for="">密码</label><input type="password" name="password" id="password" class="form-control" placeholder="请输⼊密码" required><br><label for="">重复密码</label><input type="password" name="password2" id="password2" class="form-control" placeholder="请再次输⼊密码" required maxLength="16"><br><button type="submit" class="btn btn-primary" id="btn-reg">注册</button><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-default" id="btn-reg">返回登录</a> </form></div><div class="col-md-4"></div></div></body></html>注册结果页⾯reg-submit.jsp<%@ page contentType="text/html; charset=utf-8" language="java"%><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>结果</title><link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet"></head><body><nav class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作业</a></div><div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav navbar-right"><li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登录</a></li></ul></div></div></nav><div class="container"><% String username = request.getParameter("username");String password = request.getParameter("password");String password2 = request.getParameter("password2");%><%if(password.equals(password2)){out.println("<div class='alert alert-success' role='alert'>注册成功</div>");out.println("<ul class='list-group'>");out.println("<li class='list-group-item'>⽤户名:" + username + "</li>");out.println("<li class='list-group-item'>密码:" + password + "</li>");out.println("</ul>");else{out.println("<div class='alert alert-danger' role='alert'>两次密码输⼊不⼀致,请重新输⼊</div>"); }%><!-- <%=username %><%=password %><%=password2 %> --></div>效果到此这篇关于使⽤JSP实现简单的⽤户登录注册页⾯⽰例代码解析的⽂章就介绍到这了,更多相关JSP实现简单的⽤户登录注册页⾯内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!。

JSP网上书店开发完整实例(含完整源代码)

JSP网上书店开发完整实例(含完整源代码)

完整的简单jsp网上书店详细实例计算机web编程jsp毕业论文、考试复习资料必备其中包括的详细需求、业务分析、数据库、源代码我们使用JSP和Java Bean来构建一个网上书店。

介绍的例子可以分成两大部分,第一部分是普通程序,用于客户在网上选购图书,第二部分是管理程序,用于在服务器端处理客户的定单。

客户端程序由以下几个部分构成:default.jsp:会员登录界面(首页);checklogon.jsp:检测登录代码和密码是否一致,根据由JavaBean返回的结果显示不同的信息。

BuyerBean:会员的合法性检验所用的Bean;booklist.jsp:给登录会员显示当前书店中可供选择的图书;addcart.jsp:将所选的图书加入购物车;shoppingcart.jsp:查看购物车的内容;本例的数据库采用Access(.MDB数据库),对数据库的访问采用便于理解的JDBC-ODBC方式,在使用本例前先在本地数据库建立一个ODBC数据源:bookstore。

设置步骤如下:(1)在开始->设置->控制面版(Win98、NT4.0)中选取“数据源(ODBC)”;在Win 2000 Professional和Server中分别位于“开始->设置->控制面版->管理工具”和“开始->程序->管理工具”下。

(2)启动“数据源(ODBC)”配置程序,界面如图15-1所示。

图15-1 ODBC数据源管理界面(3)在图15-1中“系统DSN”选项下单击“添加”按钮,来添加一个系统的数据源(DSN),则出现如图15-2所示数据源驱动程序选择界面:图15-2 数据源驱动程序选择界面(4)在图15-2中选择“Microsoft Access Driver (*.mdb)”单击“完成”加载Access数据库的驱动,则出现如图15-3所示数据库ODBC安装界面:图15-3 数据库ODBC安装界面(5)在图15-3中单击“选择(S)…”按钮,启动一个类似资源管理器的界面来选择数据库,如图15-4所示,在图15-4所示的界面中选择bookstore.mdb。

JSP Web应用开发案例教程课件第四章

JSP Web应用开发案例教程课件第四章
【实例4-2】 本实例使用request常用方法 getParameter(String s)获取用户提交的数字信息,并对其进 行运算后输出。
实例代码如下:
4.1 request对象
15
4.1.3 使用request对象获取用户提交的信息
<%@page contentType="text/html;charset=gb2312"%>
A request对象 B response对象 C out对象 D application对象 E session对象
5
4.1 request对象
4.1 request对象
6
4.1.1 request对象的常用方法
在JSP中,内置对象request封装了用户提交到服务器端的数据,调用该对象的相关方 法可以获取封装的信息。request对象的常用方法有很多,下面简单介绍一下。
4.1 request对象
13
4.1.2 request对象的应用
程序运行效果如图4-1所示。
图4-1 使用request对象获取的信息
4.1 request对象
14
4.1.3 使用request对象获取用户提交的信息
使用request对象获取用户信息最常用的 方法是getParameter(String s),下面通 过实例简单介绍。
while(enu.hasMoreElements()){ String Name = (String)enu.nextElement(); String value = (String)request.getParameter(Name);
} %>
</body> </html>

Jsp学生信息管理系统登录验证全代码

Jsp学生信息管理系统登录验证全代码

1.jsp登录界面 Login.jspNo.:00000000000000587 <%@page language="java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><html><head><meta http-equiv="Content-Type"content="text/html;charset=UTF-8"><title>用户登录界面</title></head><form action="LoginServlet"method="post"><body bgcolor="blue"><marquee direction="right"onmouseover="stop()"onmouseout="start()"style="font-family: 楷体_GB2312"><p><font size="10px"color="red">学生信息信息管理系统</font></p></marquee><table align=center width="237"><tr><td><table width=100%><tr><td colspan=6><font size=2><div id="b2bContent"style="FILTER: revealTrans(Duration = 1, Transition =</font></td></tr><tr><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt0"onclick="javascript:showPage(0);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">1</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt1"onclick="javascript:showPage(1);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">2</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt2"onclick="javascript:showPage(2);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">3</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt3"onclick="javascript:showPage(3);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">4</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt4"onclick="javascript:showPage(4);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">5</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt5"onclick="javascript:showPage(5);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">6</div></font></td></tr></table><script language="javascript">b2bStr = new Array();b2bStr[0]= "<div style='float:left; width:100%;overflow:hidden;'><a href=1.gif target=_blank><img src=1.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园一角 href=1.gif>太阳岛公园一角</a></div>";width:100%;overflow:hidden;'><a href=2.gif target=_blank><img src=2.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园湖光山色 href=2.gif>太阳岛公园湖光山色</a></div>";b2bStr[2] = "<div style='float:left; width:100%;overflow:hidden;'><a href=3.gif target=_blank><img src=3.gif width=214px height=145px border=0></a><br><a target=_blank title=哈尔滨雪雕 href=3.gif>哈尔滨雪雕</a></div>";b2bStr[3] = "<div style='float:left; width:100%;overflow:hidden;'><a href=4.gif target=_blank><img src=4.gif width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖 href=4.gif>镜泊湖</a></div>";b2bStr[4] = "<div style='float:left; width:100%;overflow:hidden;'><a href=5.gif target=_blank><img src=5.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园瀑布 href=5.gif>太阳岛公园瀑布</a></div>";b2bStr[5] = "<div style='float:left; width:100%;overflow:hidden;'><a href=6.gif target=_blank><img src=6.gif width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖夜色 href=6.gif>镜泊湖夜色</a></div>";var page=0;var speed=3000;function showPage(id){setTransition();b2bContent.innerHTML=b2bStr[id];b2bContent.filters.revealTrans.play();}function turnPage(){showPage(page);theTimer=setTimeout("turnPage()", speed);checkBt();page++;if(page>=6) page=0;}function checkBt(){for(var i=0;i<6;i++){btObj=eval('bt'+i);if(page==i){btObj.style.color='#FFFFFF';btObj.style.backgroundCol or='#FF781C';}else{btObj.style.color='#000000';btObj.style.backgroundColor='#F7 F7F7';}}}function setTransition(){b2bContent.filters.revealTrans.Transition=Math.round(Math.random( )*23);b2bContent.filters.revealTrans.apply();}turnPage();</script></TD></TR></table><hr color="green"width="540"><table align="center"><tr><td>用户名:<input type="text"name="username"size="8" maxlength="6"></td></tr><tr><td>密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="password"size="10"maxlength="6"></td></tr><tr><td><input type="submit"value="登录">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"value="取消"></td></table></form></body></html>2.java代码(1)User.Java 定义的属性和数据库中的字段相对应package com.softeem.dt;public class User {private int id;private String username;private String password;private String xh;private String college;public int getId(){return id;}public void setId(int id){this.id = id;}public String getUsername() {return username;}ername = username;}public String getPassword() {return password;}public void setPassword(String password) { this.password = password;}public String getXh() {return xh;}public void setXh(String xh) {this.xh = xh;}public String getCollege() {return college;}public void setCollege(String college) { this.college = college;}}(2)UserDAO.java 操作数据库tb_user,验证用户登录package com.softeem.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import com.softeem.db.DBManager;import er;public class UserDAO {/***验证用户登录*@return*/public boolean checkDenglu(User user) {boolean flag = false;// 获得数据库连接Connection conn = DBManager.getConnection();// 用select * from查询数据库中的所有字段String sql = "select count(*) from tb_user where username=? and password=?";try {PreparedStatement pst = conn.prepareStatement(sql);pst.setString(1, user.getUsername());pst.setString(2, user.getPassword());ResultSet rs = pst.executeQuery();while (rs.next()) {int count = rs.getInt(1);//用count和0比较,若大于0表示该用户存在,否则不存在if(count > 0){flag = true;}}} catch (SQLException e) {e.printStackTrace();}return flag;}}3.LoginServlet,点击登录跳转到服务器端package com.softeem.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import er;/*** Servlet implementation class LoginServlet*/public class LoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public LoginServlet() {super();}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doGet(request, response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取表单数据//处理乱码request.setCharacterEncoding("utf-8");String username = request.getParameter("username");String password = request.getParameter("password");//封装到user对象中User user = new User();user.setUsername(username);user.setPassword(password);//调用dao的checkLogin方法UserDAO dao = new UserDAO();boolean flag = dao.checkLogin(user);String message = null;String path = null;if(flag){message = "登录成功";path="success.jsp";request.getSession().setAttribute("user", user);}else{message ="对不起密码错误,请重新输入!";path="fail.jsp";}//response返回messageresponse.setCharacterEncoding("utf-8");response.getWriter().write(message);*///属于服务器跳转,浏览器地址栏没有发生改变request.getRequestDispatcher(path).forward(request,response);}}青年人首先要树雄心,立大志,其次就要决心作一个有用的人才。

基于jsp技术的企业网站

基于jsp技术的企业网站

河南机电高等专科学校毕业设计论文基于jsp技术的企业网站系部***专业***班级***学生姓名***学号***指导教师***2012年月日摘要系统尝试用JSP在网络上架构一个动态的企业网站,它是在Windows XP下,以SQL Server 2000为数据库开发平台,Tomcat网络信息服务作为应用服务器,MyEclipse为开发工具,采用HTML、javascript,CSS控制样式前台界面设计,采用JSP(Java Server Pages)技术开发的企业门户网站。

系统分前台部分和后台部分,前台部分由用户使用,主要包括客户登录,客户注册,商品选购(可按分类方式查询商品,或通过关键字查询),购物车管理,查看用户订单,用户个人信息修改等功能。

后台部分由管理员使用,主要包括查看更改招聘信息,业务订单管理(查看订单清单,更新订单付款,删除订单),用户信息管理(修,删,查),发布新产品等功能。

建立后的网站系统是一个动态、交互式、具有商品提供、系统管理功能的电子商务网站。

关键字:企业;Tomcat;SQL Server;动态网页;JSP;JDBC-ODBC目录第1章绪论 (1)1.1引言 (1)1.2课题的目的和意义 (1)第2章系统开发技术和环境 (3)2.1网站开发工具-M Y E CLIPSE6.0 (3)2.2服务器T OMCAT6.0简介 (3)2.3数据库SQL S ERVER 2000简介 (3)2.4JSP技术工作原理 (4)2.4.1JSP技术简介 (4)2.4.2JSP技术的优点 (4)2.4.3J AVA S ERVLET概述 (5)2.4.4J AVA B EAN简介 (5)2.5网站开发模式 (6)2.6本章小结 (7)第3章系统分析 (8)3.1设计目标 (8)3.2可行性分析 (8)3.2.1经济可行性 (8)3.2.2技术可行性 (9)3.2.3社会可行性 (9)3.3网站的需求分析 (9)3.3.1相关网站的功能构架的考察 (9)3.3.2网站的设计 (10)3.3.3网站设计的特点 (10)3.3.4网站开发的设计思想 (10)3.3.5系统设计总的原则 (11)3.4本章小结 (11)第4章系统的总体设计 (11)4.1购产品系统功能分析 (11)4.2功能模块的设计 (12)4.3系统流程分析 (12)4.4系统数据库设计 (15)4.4.1数据库设计分析 (15)第1章绪论1.1 引言目前,网络正以一种前所未有的冲击力在影响着人类的活动,包括人类的生产和日常生活。

JSP-简单的登录实现

JSP-简单的登录实现
application.setAttribute("count", new Integer(0));}
Integer c1 = (Integer) application.getAttribute("count"), c2 = new Integer(
c1.intValue() + 1);
application.setAttribute("count", c2);
String username = request.getParameter("username");
String password = request.getParameter("password");
String id = request.getParameter("id");
String authcode = request.getParameter("authcode");
<tr><td colspan="2" align="center"><input type="submit" value="LOGIN" />
</td></tr>
</table></form>
......
Welcome.jsp:
<%
if (((String)request.getParameter("submit"))!=null) {
......
<%
if (((String) request.getParameter("submit")) != null) {

JSP使用MD5加密进行登录验证

JSP使用MD5加密进行登录验证

JSP使用MD5加密进行登录验证使用MD5加密进行登录验证是常见的一种方式,本文将详细介绍如何在JSP中使用MD5加密进行登录验证。

一、什么是MD5加密MD5是一种常用的加密算法,它将任意长度的数据转化为固定长度的密文,且不可逆。

即使输入数据只发生了一个字符的改变,也会导致加密后的密文发生巨大的变化,因此MD5加密是一种非常安全的加密方式。

在应用中,用户的账号和密码都是敏感信息,为了保护用户的隐私,通常会对用户的密码进行加密保存。

使用MD5加密是一种常见的方式,因为MD5加密后的密文很难被破解,即使被黑客获取到密文,也无法还原出原始密码。

三、如何在JSP中使用MD5加密1. 引入MD5加密算法的Java类库在JSP中,我们可以使用Java提供的MessageDigest类来实现MD5加密。

首先,需要引入java.security.MessageDigest类库,在JSP页面的顶部添加如下代码:```java```2.创建MD5加密方法创建一个方法来实现MD5加密,代码如下:```javapublic String md5Encryption(String input) throws ExceptionMessageDigest messageDigest =MessageDigest.getInstance("MD5");byte[] digest = messageDigest.digest(input.getBytes();StringBuilder result = new StringBuilder(;for (byte b : digest)result.append(String.format("%02x", b & 0xff));}return result.toString(;```这个方法接受一个输入参数,将其转换为字节数组后再进行加密计算,最后将结果转换为十六进制字符串形式返回。

JSP步骤 简单实例

JSP步骤 简单实例

上机一 WEB 应用开发环境配置内容:搭建JSP工作环境,主要包括Java JDK的安装、Tomcat服务器的安装和构建班级论坛的第一个JSP的index.jsp首页面。

1. 安装JDK的步骤如下找到jdk-6-windows-i586.exe 运行安装程序,设定安装路径为D:\学习软件\jdk1.6.0, 其余接受默认安装。

安装结束后就要配置环境变量,包括java_home,path和classpath的设置,操作步骤如下:1)用鼠标右击“我的电脑”,选择“属性”,→“高级”→“环境变量”→“系统变量”→“新建”→在“变量名”输入框中写入“java_home”,在“变量值”输入框中写入“D:\学习软件\jdk1.6.0”→点击“确定”。

2)选中“系统变量”查看是否有classpath项目,如果没有就点击“新建”,→如果已经存在就选中classpath选项,→点击“编辑”按钮,→然后在“变量名”中填写“classpath”,→在“变量值”中填写“.;D:\学习软件\jdk1.6.0\lib;D:学习软件\jdk1.6.0\jre\lib”。

在“path”设定时,“变量名”输入框填写“path”,“变量值”输入框填写“D:\学习软件:\jdk1.6.0\bin”3)打开命令提示符窗口,输入命令“java -version”,看到Java版本的信息,确定安装完成。

2. 安装Tomcat6步骤如下将apache-tomcat-6.0.18.zip从磁盘中解压到D:\学习软件盘符下在D:\学习软件\apache-tomcat-6.0.18\bin目录下双击“startup.bat”启动服务器,双击“shutdown.bat”关闭服务器。

在环境变量中添加“变量名”为“tomcat_home”,“变量值”为“D:\学习软件\apache-tomcat-6.0.18”的设定。

在启动服务器后,打开浏览器,在地址栏输入http://localhost:8080查看,如出现主页,则表示安装成功。

简单的在线考试系统(JSP+MysqL)

简单的在线考试系统(JSP+MysqL)

北方民族大学课程设计报告系(部、中心)计算机科学与工程学院姓名于淼学号20113185专业计算机科学与技术班级(2)班同组人员尚娜、农晓蕾、杨柳课程名称网络程序设计设计题目名称在线考试系统起止日期 2013.10.10-2013.12.8 成绩________________________________指导老师签名________________________在线考试系统摘要基于Web的在线考试系统——随着计算机及网络技术的飞速发展,Internet/Intranet应用在全球范围内日益普及,当今社会正快速向信息化社会前进,信息自动化的作用也越来越大,从而使我们从繁杂的事务中解放出来,提高了我们的工作效率。

在众多的网络服务中,Web 给人耳目一新的感觉,而在这其中,JSP技术和基于Struts框架技术则因为可以进行复杂的数据库操作、很强的交互性以及方便用户控制和管理备受青睐。

目前存在各级各类的考试,而它们的各种工作主要还是依赖于手工完成,手工管理还存在这许多弊端,由于不可避免的人为因素,造成数据的遗漏、误报。

计算机信息化管理有着储存量大,速度快等许多优点,因此我们可以利用计算机网络,利用ASP技术实现动态的管理。

随着计算机网络技术的进一步发展和普及,利用JSP技术开发的各种网络在线考系统必将大行其道。

关键字:JSP技术;Struts ;在线考试系统目录:1、在线考试系统的需求分析 (4)1.1硬件,软件环境说明 (4)1.1.1硬件环境说明 (4)1.1.2软件环境说明 (4)1.1.3在线考试系统网站的技术说明 (7)1.1.3.1关于对B/S架构的理解 (7)1.1.3.2B/S架构带来的巨大好处 (8)1.2功能需求分析 (8)2、在线考试系统的总体规划与结构框图 (8)2.1在线考试系统总体设计 (8)2.2在线考试系统的总体规划设计 (8)2.2.1学生模块 (9)2.2.2管理员模块 (9)2.3在线考试系统各个模块之间的关系图及动作分解 (10)2.3.1各个子模块之间的关系和操作动作分解 (10)2.3.2管理员模块下各个子模块之间的关系及动作分解 (10)3、在线考试系统数据库设计 (11)3.1数据库的需求分析 (11)3.2在线考试系统概念结构设计 (11)3.2.1在线考试系统数据库的实体设计 (11)3.2.2在线考试系统数据库的E-R图 (12)3.3数据库的逻辑结构设计 (13)3.3.1在线考试系统数据库逻辑结构设计 (13)4、针对具体的功能模块写出设计流程图与关键的程序代码 (14)4.1在线考试系统设计流程图 (14)4.2在线考试系统管理模块设计流程图 (14)4.3在线考试系统用户登录模块设计 (15)4.4系统关键程序代码 (16)4.4.1dl.jsp源代码 (16)4.4.2zc.jsp源代码 (18)4.4.3zxks(1).jsp源代码 (23)4.4.4xgzl.jsp源代码 (26)4.4.5htdl.jsp源代码 (31)4.4.6gl_student.jsp源代码 (33)4.4.7gl_addstudent.jsp源代码 (35)4.4.8gl_lesson.jsp源代码 (40)4.4.9gl_addlesson.jsp源代码 (42)4.4.10gl_timu.jsp源代码 (46)4.4.11gl_addtimu源代码 (48)5.测试和演示系统并抓取图形界面 (53)5.1系统开发与运行环境的配置 (53)5.1.1JDK的安装与配置 (53)5.1.2Tomcat的安装与配置 (53)5.1.3Dreamweaver CS3的站点的配置 (53)5.2演示系统并抓取系统图形界面 (58)6、测试结果及存在的问题 (65)6.1测试的结果 (65)6.2存在的问题 (66)7、参考文献 (66)1.在线考试系统的需求分析1.1硬件、软件环境说明1.1.1硬件环境说明在线考试系统的硬件环境是:CPU采用的是Inter(R)Core(TM)i3-2330M CPU@2.20GHz;硬盘容量:500GB;显示器的分辨率是1366×768。

jsp毕业设计源代码

jsp毕业设计源代码

jsp毕业设计源代码JSP毕业设计源代码随着互联网的发展,越来越多的学生选择使用JSP(JavaServer Pages)作为毕业设计的开发语言。

JSP是一种用于开发动态网页的技术,它结合了Java代码和HTML标记,使开发者能够在网页中嵌入Java代码,实现复杂的逻辑和交互功能。

在这篇文章中,我们将探讨一些常见的JSP毕业设计源代码,以帮助学生更好地理解和运用这一技术。

1. 用户注册和登录系统一个常见的JSP毕业设计项目是开发一个用户注册和登录系统。

这个系统允许用户注册一个新账号,并使用注册的账号和密码登录。

在JSP中,我们可以使用Java代码来处理用户的输入和验证,然后将用户信息存储在数据库中。

以下是一个简单的示例代码:```java<%@ page import="java.sql.*" %><%String username = request.getParameter("username");String password = request.getParameter("password");// 连接数据库String url = "jdbc:mysql://localhost:3306/mydatabase";String dbUsername = "root";String dbPassword = "password";Connection conn = DriverManager.getConnection(url, dbUsername,dbPassword);// 检查用户名和密码是否正确String sql = "SELECT * FROM users WHERE username=? AND password=?"; PreparedStatement statement = conn.prepareStatement(sql);statement.setString(1, username);statement.setString(2, password);ResultSet result = statement.executeQuery();if (result.next()) {// 登录成功session.setAttribute("username", username);response.sendRedirect("home.jsp");} else {// 登录失败out.println("用户名或密码错误");}// 关闭数据库连接result.close();statement.close();conn.close();%>```2. 在线购物系统另一个常见的JSP毕业设计项目是开发一个在线购物系统。

jsp项目开发案例

jsp项目开发案例

jsp项目开发案例JSP项目开发案例。

在现代的互联网时代,JSP(Java Server Pages)作为一种动态网页开发技术,已经被广泛应用于各种Web应用程序的开发中。

它能够与Java语言完美结合,通过简单的标签和脚本语言,实现动态生成网页内容的功能。

在本文中,我们将以一个简单的JSP项目开发案例为例,来介绍JSP的基本开发流程和一些常用的技术。

首先,我们需要明确我们的项目目标。

在这个案例中,我们将开发一个简单的在线图书销售网站。

用户可以在网站上浏览图书信息,并进行购买。

我们的任务是开发一个能够实现这一功能的JSP网站。

第一步,我们需要准备好开发环境。

首先,确保你的计算机上已经安装好了Java开发环境(JDK)和一个Web服务器(比如Tomcat)。

然后,创建一个新的Web项目,配置好项目的基本信息和目录结构。

接下来,我们开始编写JSP页面。

我们首先创建一个用于显示图书信息的页面,命名为“bookList.jsp”。

在这个页面中,我们使用JSP的标签和脚本语言,从后台数据库中获取图书信息,并将其显示在页面上。

同时,我们还需要在页面上添加一些交互功能,比如搜索框和购买按钮。

在“bookList.jsp”页面完成后,我们继续创建一个用于显示购物车信息的页面,命名为“shoppingCart.jsp”。

在这个页面中,我们将实现用户添加图书到购物车、修改购物车内容和结算购物车的功能。

通过JSP的标签和脚本语言,我们可以很方便地实现这些功能,并将购物车的信息动态显示在页面上。

除了页面的开发,我们还需要编写一些后台的Java代码。

比如,我们需要创建一个用于处理用户请求的Servlet,并编写相应的业务逻辑代码。

通过Servlet,我们可以接收用户的请求,并调用后台的Java代码来处理这些请求,最终返回相应的结果给前端页面。

最后,我们需要部署和测试我们的JSP项目。

将项目部署到Web服务器上,并启动服务器。

JSP在线聊天室系统

JSP在线聊天室系统

西安学院本科毕业论文(设计)题目:基于JSP的在线聊天室的设计与实现学生姓名:指导教师:所在分院:专业:软件工程班级:二O一五年五月基于JSP的在线聊天室的设计与实现摘要:在今天来看,在线聊天室系统是一个受广大用户所热爱的web动态应用程序。

使用聊天室,用户们能够即时的相互联系。

但由于的需要和设计的不同,聊天室程序的实现方法也有很多差异。

本文中的在线聊天室系统主要用的是Jsp+Servlet+Ajax+Html5技术开发的。

其中系统开发的主要功能包括:会员的注册、会员的登录、游客登录、聊天区消息即时显示、名单区是显示在线的用户的地方。

其中的会员注册和登录采用了javascript技术来对文本框中未输入用户名的地方进行了效验。

本系统的聊天区域与传统的定时刷新用户聊天消息所有的技术不同,是采用了Ajax技术来即时的刷新各个用户的聊天消息,这样就方便了其他用户在线查看其他用户和自己的聊天信息,另外用户在进行聊天的时候能够按根据自己的喜好来设置聊天消息的字体,颜色以及心情表情等。

本系统通过使用MyEclipse这个开发工具,实现了登录、注册及聊天区的页面,另外,经过使用MySQL数据库和JDBC技术实现了对会员信息的保存。

关键词: 在线聊天室;Jsp;AjaxThe design and implementation based onJSP online chat roomsAbstract: In today's view, online chat system is a dynamic web application that is loved by the masses of users. Use chat rooms, users can immediately contact each other. But, due to the different requirements and design of the chat program implementation way also have many differences. In this paper, the online chat system is mainly used Jsp + Servlet + Ajax + HTML 5 technology development. The main functions of the system development including: member registration, login, visitors login, display real-time chat messages, online user name display list area. The member registration and login using javascript to do not enter the user name text box where the efficacy. The chat areas of this system and the traditional timing refresh user chat messages to all technology, Ajax technology is adopted to instantly refresh every user chat messages, so it is convenient for other users to see other users and their online chat messages, other users at the start of chat of time can be set up according to his be fond of chat message font, color and mood expression, etc.This system by using the MyEclipse development tools, the realization of the login, registration, and the pages of chat area, in addition, after using the MySQL database and JDBC technology implements the membership information preservation.Keywords: Online chat rooms;Jsp;Ajax目录1 绪论 (1)1.1研究背景 (1)1.2课题意义 (1)1.3本文主要内容 (2)2 相关技术介绍 (3)2.1JSP技术概述 (3)2.2A JAX技术概述 (4)2.3B/S架构与C/S架构的概述 (5)2.3.1 B/S架构 (5)2.3.2 C/S架构 (5)2.4J A V A B EAN技术简介 (7)2.5JDBC技术的种类 (7)3需要分析 (9)3.1可行性分析 (9)3.1.1 技术可行性分析................................... ................................................ .. (9)3.1.2 经济可行性分析 (9)3.1.3 社会因素可行性分析 (9)3.2数据流图 (9)3.3项目程序图 (10)3.4数据字典 (10)4总体设计 (12)4.1整体设计过程 (12)4.2聊天系统的基本原理 (12)4.3系统的总体结构图 (13)4.4用例图 (14)4.5数据表的设计 (14)4.6数据库连接设计 (15)4.7运行环境与硬件的配置 (16)5详细设计 (20)5.1聊天室系统详细功能 (20)5.2聊天室登录模块实现 (20)5.3聊天室注册模块实现 (22)5.4聊天室模块实现 (24)5.5KINDEDITOR插件的采用 (27)5.6在线用户列表模块实现 (28)6 系统测试 (29)6.1功能测试 (29)6.1.1 聊天室登录和注册测试 (29)6.1.2 消息发送测试 (30)6.1.3 用户在线状态测试 (30)6.2中文乱码的测试 (30)总结 (31)致谢 (32)参考文献 (33)1 绪论1.1研究背景就最近的几年来看,随着计算机和网络在国内的大量普及,网站的高可扩展性,便于部署,方便维护等特点就成为了主流发展方向,过去的web网站采用的是同步交互的技术,也就是客户端首先向web服务器提交请求,服务器在得到请求之时,客户端还处在等待状态,有时候若超出了服务器的处理时段,结果就会出现返回页面不能用等错误提示,这样是非常令人头疼的。

jsp注册登录页面代码

jsp注册登录页面代码

jsp注册页面代码用户信息的bean:package chen;public class UserBean{private String userid;private String password;public void setUserId(String userid){erid=userid;}public void setPassword(String password){this.password=password;}public String getUserId(){return erid;}public String getPassword(){return this.password;}}提交数据库的bean:package chen;import com.mysql.jdbc.Driver;import java.sql.*;public class UserRegister{private UserBean userBean;private Connection con;//获得数据库连接。

public UserRegister(){String url="jdbc:mysql://localhost/"+"chao"+"?user="+"root"+"&password="+"850629"; try{Class.forName("com.mysql.jdbc.Driver").newInstance();con = DriverManager.getConnection(url);}catch(Exception e){e.printStackTrace();}}//设置待注册的用户信息。

public void setUserBean(UserBean userBean){erBean=userBean;}//进行注册public void regist() throws Exception{String reg="insert into userinfo(userid,password) values(?,?)";try{PreparedStatement pstmt=con.prepareStatement(reg);pstmt.setString(1,userBean.getUserId());pstmt.setString(2,userBean.getPassword());pstmt.executeUpdate();}catch(Exception e){e.printStackTrace();throw e;}}}提交注册数据进入数据库:<%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312" import="chen.*" %><jsp:useBean id="userBean" class="erBean" scope="request"><jsp:setProperty name="userBean" property="*"/></jsp:useBean><jsp:useBean id="regist" class="erRegister" scope="request"/><html><head><title> 用户信息注册页面</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body>String userid =request.getParameter("userid");String password = request.getParameter("password");userBean.setUserId(userid);userBean.setPassword(password);System.out.println(userid+password);%><% try{regist.setUserBean(userBean);out.println(userid);regist.regist();out.println("注册成功");}catch(Exception e){out.println(e.getMessage());}%><br><a href="login.jsp">返回</a></body></html>登陆验证页面:<%@page import="java.sql.*" contentType="text/html;charset=GB2312" %><%@page import="java.util.*"%><%String userid1=new String(request.getParameter("userid"));String password1=new String(request.getParameter("password"));Class.forName("com.mysql.jdbc.Driver");Connectioncon=DriverManager.getConnection("jdbc:mysql://localhost:3306/chao","root","850629"); Statement stmt=con.createStatement();String sql="select * from userinfo where userid='"+userid1+"';";ResultSet rs=stmt.executeQuery(sql);if(rs.next()){String password=new String(rs.getString("password"));if(password.equals(password1)){session.setAttribute("userid1",userid1);response.sendRedirect("sucess.jsp");}else{response.sendRedirect("login.jsp");}}else{response.sendRedirect("login.jsp");%>登陆页面:<%@ page contentType="text/html; charset=gb2312" %><html><body><form method="get" action="checklogin.jsp"><table><tr><td> 输入用户名:</td><td><input type=text name=userid ></td></tr><tr><td>输入密码:</td><td><input type=password name=password></td></tr><tr><td><input type=submit value=确认></td></tr></table></form><form action="register.jsp"><input type=submit value=注册></form></body></html>注册页面:<%@page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.io.*"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body><center><h1>注册新用户</h1><form action="adduser.jsp" method=post><table border="1" bgcolor="#0099CC"><tr><td> 用户名:<input type="text" name="userid"></td></tr><tr valign="middle"><td> 密码:<input type="password" name="password" readonly></td></tr><tr><td><input type=submit value=提交></td></tr></table></form></center></body></html>登陆成功页面:<%@page import="java.util.*" contentType="text/html; charset=gb2312" %> <%@include file="trans.jsp"%><html><head><title>sucess</title></head><body bgcolor="#ffffff"><h1>登录成功,欢迎您!</h1><%=trans(session.getAttribute("userid1"))%></body></html>登录前台界面设计代码如下:<%@ page contentType="text/html; charset=gb2312"language="java" import="java.sql.*" errorPage="" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN"><html><head><title>Register Test!</title></head><body>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登录界面!! <br><form method="post" action="cheklogin.jsp" name="form"> <table width="183" height="85" border="1"><tr><td>User:</td><td><input type="text" name="user" size="13"> </td></tr><tr><td>Password:</td><td><input type="Password" name="password" size="13" > </td></tr><tr><td><input type="Submit" name="bt1" text="OK" value="登录"></td><td><a href="do_register.jsp" target="_parent">新用户注册<br></a></td></tr></table></form></body></html>后台处理程序添加一个Jsp 右键webRoot : New—>JSP 名称cheklogin .jsp代码如下:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><%String path = request.getContextPath();String basePath =request.getScheme()+"://"+request.getServerName()+":"+req uest.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'cheklogin.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><%String usr = request.getParameter("user");String pwd = request.getParameter("password");//String usr = "hurui";//String pwd = "free889";Connection con = null;Statement sm = null;ResultSet rs = null;try{Class.forName("rmix.jdbc.IfxDriver").newInstan ce(); //装载jdbc 驱动String url ="jdbc:informix-sqli://192.168.5.249:9003/testuser:informi xserver=iservice_online_net"; // 定义数据库连接URLcon =DriverManager.getConnection(url,"informix","informix"); //获取数据连接实例sm = con.createStatement(); //获取Statement 的实例rs = sm.executeQuery("select * from new_test_user where login='"+usr+"' and password='"+pwd+"'"); //执行查询语句,并返回给结果集}catch(Exception e){e.printStackTrace( );}//添加表格%><table border="1" width="80%"><tr><td>你的用户名是:</td><td>你的密码是:</td></tr><%while (rs.next()) { //循环输出产品信息String var_name=rs.getString(1);String var_val=rs.getString(2);%><tr><%if(usr == var_name || pwd ==var_val){System.out.println("success!");}%><td><%= var_name %></td><td><%= var_val %></td></tr><%}rs.close();sm.close();con.close();%></body></html>验证试验是否成功:输入:用户名:admin密码:11111。

登录的JSP源代码

登录的JSP源代码

Login.jsp<%@ page language="java" pageEncoding="UTF-8"%><html><head><title>读书会</title></head><body bgcolor="#E3E3E3"><form action="MainServlet" method="post"><table><caption>用户登录</caption><tr><td>登录名:</td><td><input ty pe="text" name="username" size=”20”/></td></tr><tr><td>密码:</td><td><input type="password" name="pwd" size=”21”/></td></tr> </table><input type="submit" value="登录"/><input type="reset" value="重置"/></form>如果没注册单击<a href="register.jsp">这里</a>注册!</body></html>DB.javapublic class DB {Connection ct;PreparedStatement pstmt,p1;static int id;static int i,n;//为插入用户和留言统计记录// 在构造函数中建立与数据库的连接,这样在建立DB对象时就连接了数据库//数据库操作失败,会导致服务器弹出下载servlet的提示框// 注意sql语句错误引起的数据不一致.public DB(){try {Class.forName("com.mysql.jdbc.Driver");ct=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","1234");pstmt=ct.prepareStatement("select count(*) from lyTable ");ResultSet rs=pstmt.executeQuery();rs.next();i=rs.getInt(1);pstmt=ct.prepareStatement("select count(*) from userTable ");rs=pstmt.executeQuery();rs.next();n=rs.getInt(1);} catch (Exception e) {e.printStackTrace();}}// 根据username和password查询用户,查到就返回该对象,没有就返回nullpublic User checkUser(String username,String password){try{pstmt=ct.prepareStatement("select * from userTable where username=? and password=?");pstmt.setString(1, username);pstmt.setString(2, password);ResultSet rs=pstmt.executeQuery();User user=new User();while(rs.next()){user.setId(rs.getInt(1));user.setUsername(rs.getString(2));user.setPassword(rs.getString(3));return user;}return null;}catch(Exception e){e.printStackTrace();return null;}}MainServlet.javaimport db.DB;public class MainServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// 设置请求编码request.setCharacterEncoding("Utf-8");// 设置响应编码response.setContentType("Utf-8");// 获得JSP页面输入的用户名的值String username=request.getParameter("username");// 获得JSP页面输入的密码的值String pwd=request.getParameter("pwd");// 建立DB类对象,使用其中的方法来完成判断DB db=new DB();// 获得session对象,用来保存信息HttpSession session=request.getSession();// 先获得user对象,如果是第一次访问该Servlet,用户对象肯定为空,但如果是第// 二次甚至是第三次,就不应该再判断该用户的信息User user=(User) session.getAttribute("user");// 这里就是判断,如果用户是第一次进入,调用DB类中的方法判断if(user==null){user=db.checkUser(username, pwd);}// 把user对象存在session中session.setAttribute("user", user);if(user!=null){// 如果根据查询,用户不为空,表示用户名和密码正确,应该去下一界面// 这里是去主界面,主界面中包含了所有留言信息,所以要从留言表中查出来ArrayList al=db.findLyInfo();// 把查询的信息保存在session中session.setAttribute("al", al);// 然后跳转到我们要去的主界面response.sendRedirect("main.jsp");}else{// 如果用户名和密码错误,回到登录界面response.sendRedirect("login.jsp");}。

JSP实现简单注册功能(一)

JSP实现简单注册功能(一)

对于任何一个互动性较强的网站,我们都需要一个用户的参与,同时也就需要提供用户注册功能,在这里简单用jsp实现一个注册功能的小程序,采用的是mysql数据库,数据库名为test,表名users。

其users表中的字段分别为name,password,那么设置为主键,建表不做详细介绍了,傻瓜式操作。

这里我们需要建立两个页面,第一个reg.html注册页面,regaction.jsp逻辑操作页面。

下面是程序代码:Reg.html(完全是一个展示页面,很简单)<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>reg.html</title><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description"content="this is my page"><meta http-equiv="content-type"content="text/html; charset=UTF-8"><!--<link rel="" type="text/css" href="">--></head><body><form action="regaction.jsp" method="post"><table width="400"align="center"border="1"cellpadding="0" cellspacing="0"><tr><td colspan="2"align="center">用户注册</td></tr><tr><td>name:</td><td><input type="text" name="username"/></td></tr><tr><td>password:</td><td><input type="text" name="password"/></td></tr><tr><td colspan="2"align="center"><input type="submit"value="注册"/></td></tr></table></form></body></body></html>这里提供了两个文本框,用来取得用户注册信息。

web JSP 简单的登录+注册页面代码

web JSP 简单的登录+注册页面代码

简单做了界面,代码功能应该没有问题,简单做个文档分享一下。

登录界面denglu.jsp:<%@page contentType="text/html;charset=gb2312" %><html><head><title>登录界面</title><script>function check(){if(erN.value==""){alert("用户名不能为空");erN.focus();return false;}if(erP.value==""){alert("密码不能为空");erP.focus();return false;}document.dlForm.submit();return true;}</script></head><body><center><font size="6"> 欢迎进入登录界面</font><form action="dlhou.jsp" onsubmit="return check()" method="post" name="dlForm"><p>用户名:<input type="text" name="UserN" style="width: 148px; "/></p><p>密&nbsp;&nbsp;码:<input type="password" name="UserP" style="width: 146px; "/></p><p><input type="submit" value="&nbsp;登&nbsp;&nbsp;录&nbsp;" style="height: 43px; "/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="忘记密码" onclick="parent.location.href('wangji.jsp')" style="height: 43px; "/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回主页" onclick="parent.location.href('welcome.jsp')" style="height: 43px; "/></p></FORM> </center></body></html>dlhou.jsp<%@page contentType="text/html;charset=gb2312" %><%@page language="java" import="java.sql.*" %><jsp:useBean id="SQLbean" scope="session" class="lian.Lian"/><html><head><title>登录状态</title></head><body><div align="center"><span class="style1">登录状态</span><br><hr><br></div><%String userN=request.getParameter("UserN");String userP=request.getParameter("UserP");// out.print(userN);String sql="select * from yxx where yname='"+userN+"'";SQLbean.OpenConn();ResultSet rs=SQLbean.executeQuery(sql);if(!rs.next()){%><script>alert("用户名不存在!");window.location.href="denglu.jsp";</script><%}// while(rs.next()){String p=rs.getString("ypassword").trim();if(p.equals(userP.trim()))// response.sendRedirect("zhu.jsp?param="+userN);{session.setAttribute("yhm",userN);// response.sendRedirect("zhu.jsp");%><script>alert("恭喜您,登录成功!");window.location.href="zhu.jsp";</script><%}else{%><script>alert("密码错误!");window.location.href="denglu.jsp";</script><%}}rs.close();SQLbean.closeSt();SQLbean.closeConn();%></body></html><%@page contentType="text/html;charset=gb2312" %><html><head><title>注册界面</title><script>function zcheck(){if(erN.value==""){alert("用户名不能为空");erN.focus();return false;}if(erP.value==""){alert("密码不能为空");erP.focus();return false;}if(document.zcForm.reUserP.value==""){alert("确认密码不能为空");document.zcForm.reUserP.focus();return false;}if(document.zcForm.reUserP.value!=erP.value){alert("确认密码和密码不符");document.zcForm.reUserP.focus();return false;}return true;}</script></head><body><center><font size="6"> 欢迎进入注册界面</font><br><br><font size="4"> 基本信息注册</font><form action="zchou.jsp" onsubmit="return zcheck()" method="post" name="zcForm"><p>&nbsp;&nbsp;&nbsp;用户名:&nbsp;&nbsp;<input type="text" name="UserN" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p><p>&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="UserP" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p> <p>&nbsp;&nbsp;&nbsp;确认密码:<input type="password" name="reUserP" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p><p>&nbsp;&nbsp;&nbsp;性&nbsp;&nbsp;&nbsp;&nbsp;别:&nbsp;&nbsp;&nbsp;<input type="radio" name="UserS" value="Mr." checked="checked"/>男&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="UserS" value="Ms."/>女&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">*</font></p><p>年&nbsp;&nbsp;&nbsp;&nbsp;龄:<input type="text" name="UserA" style="width: 155px; "/></p><br><font size="4"> 密码找回问题设置</font><p>问题1:你最尊敬的老师是?答案1:<input type="text" name="Q1" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p><p>问题2:你最喜欢的学科是?答案2:<input type="text" name="Q2" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p><p>问题3:你最喜欢的运动是?答案3:<input type="text" name="Q3" style="width: 155px; "/>&nbsp;&nbsp;<font color="red">*</font></p><p><input type="submit" name="确定" value="&nbsp;确&nbsp;&nbsp;定&nbsp;" style="height: 33px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回主页" onclick="parent.location.href('welcome.jsp')" style="height: 33px; "/></p></form></center></body></html><%@page contentType="text/html;charset=gb2312" %><%@page language="java" import="java.sql.*" %><jsp:useBean id="SQLbean" scope="session" class="lian.Lian"/><html><head><title>注册状态</title></head><body><%String userN=request.getParameter("UserN");String userP=request.getParameter("UserP");String userS=request.getParameter("UserS");String userA=request.getParameter("UserA");String q1=request.getParameter("Q1");String q2=request.getParameter("Q2");String q3=request.getParameter("Q3");SQLbean.OpenConn();String sqly="select * from yxx where yname='"+userN+"'";ResultSet rsy=SQLbean.executeQuery(sqly);if(rsy.next()){%><script>alert("用户名已被注册,请更换用户名");window.location.href="zhuce.jsp";</script><%}else{String sql="insert into yxx values('"+userN+"','"+userP+"','"+userS+"','"+userA+"')";String sql2="insert into yyz values('"+userN+"','"+q1+"','"+q2+"','"+q3+"')";SQLbean.executeUpdate(sql);SQLbean.executeUpdate(sql2);SQLbean.closeSt();SQLbean.closeConn();%><script>alert("注册成功,将跳转登录界面");window.location.href="denglu.jsp";//wrq经试验表明sendRedirect()还没显示alert 提示就已经跳转</script><%}%></body></html>。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
}
}
//获取密码
String sPasswd = request.getParameter ( "txtPassword" );
if ( sPasswd == "" || sPasswd == null || sPasswd.length()>20 )
//连接参数与Access不同
String url = "jdbc:mysql://localhost/LearnJSP";
//建立连接
Connection connection = DriverManager.getConnection ( url, "root",
<meta http-equiv="Content-Language" content="ch-cn">
</head>
<body>
<!-- Form 用来提取用户填入并提交的信息-->
<form method="post" name="frmLogin" action="verifylogin.jsp">
<script language="javaScript">
function validateLogin()
{
var sUserName = document.frmLogin.txtUserName.value;
var sPassword = document.frmLogin.txtPassword.value;
<input type="password" name="txtPassword" value="Your password"
onfocus="if(this.value=='Your password')this.value='';"><br>
<input type="submit" name="Submit" value="提交" onClick="validateLogin();" >
//登记JDBC驱动程序
Class.forName ( "org.gjt.mm.mysql.Driver" ).newInstance ( );
//连接参数与Access不同
String url = "jdbc:mysql://localhost/LearnJSP";
{
try
{
response.sendRedirect ( "login.html" );
} catch ( Exception e )
{
}
}
//登记JDBC驱动程序
Class.forName ( "org.gjt.mm.mysql.Driver" ).newInstance ( );
<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="zieckey,jsp">
<html>
<head>
<title>登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
}
rs.close ( );
stmt.close ( );
connection.close ( );
%>
</body>
</html>
下面为客户端添加代码验证功能:
<html>
<head>
<title>登录</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<h1 align="center">用户登录</h1><br>
<div align="center">用户名:
<input type="text" name="txtUserName" value="Your name"
onfocus="if(this.value=='Your name')this.value='';"><br>密码:
------------------Jsp Login页面(配合数据库)
前台login.html和后台verifylogin.jsp两个页面组成:
login.html内容:
<html>
<head>
<title>登录</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" name="Reset" value="重置"><br>
</div>
</form>
<!-- javaScript 函数 validateLogin(),用来验证用户名和密码是否为空 -->
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录</title>
if ( sUserName == "" || sUserName == null || sUserName.length()>20 )
{
try
{
response.sendRedirect ( "login.html" );
} catch ( Exception e )
<meta http-equiv="description" content="Test JSP using MySQL">
</head>
<body>
<div align=center>
<%
//获取用户名
String sUserName = request.getParameter ( "txtUserName" );
<meta http-equiv="Content-Language" content="ch-cn">
</head>
<body>
<!-- Form 用来提取用户填入并提交的信息-->
<form method="post" name="frmLogin" action="verifylogin.jsp">
<h1 align="center">用户登录</h1><br>
<div align="center">用户名:
相关文档
最新文档