JSP学习笔记(三)-----使用JSP处理用户注册和登陆
1. 这是一个JSP实例,由四个JSP页面组成,处理用户的注册和登陆信息2. 首先是login.jsp,代码如下: 织梦好,好织梦<html>
3. test.jsp代码如下:(主要处理用户注册,将注册信息插入数据库)
<center>
<form method=get action="http://127.0.0.1:8000/jsp/test.jsp">
username<input type=text name=username>
<br><br>
password<input type=password name=pass>
<br><br>
<input type=submit value="注册">
</form>
<form method=get action="http://127.0.0.1:8000/jsp/test3.jsp">
username<input type=text name=username>
<br><br>
password<input type=password name=pass>
<br><br>
<input type=submit value="登陆">
</form>
<br>
</center>
</html><html>
<%@ page language="java" import="java.sql.*"%>
your username is:<%=request.getParameter("username")%>
<br><br>
your password is:<%=request.getParameter("pass")%>
<br><br>
<%
String name=request.getParameter("username");
String pass=request.getParameter("pass");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection dbcon=DriverManager.getConnection("jdbc:odbc:test","sa","");
PreparedStatement stat=dbcon.prepareStatement(
"insert login values(?,?)");
stat.setString(1,name);
stat.setString(2,pass);
stat.executeUpdate();
out.println("<br><br><B>insert successful</B>");
}
catch(Exception e)
{
out.println(e);
}
%>
<b>Click here to view all people</b>
<form method=get action="http://127.0.0.1:8000/jsp/test2.jsp">
<input type=submit value="--->">
</form>
</html>
4. test2.jsp,代码如下:(处理当用户注册成功之后可以查看所有的注册用户名单)
<html>
<%@ page language="java" import="java.sql.*"%>
<% try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection dbcon=DriverManager.getConnection("jdbc:odbc:test","sa","");
PreparedStatement stat=dbcon.prepareStatement(
"select * from login");
文章评论
共有位Admini5网友发表了评论 查看完整内容