资源简介
这个文件包,包括Register与TestLogin,Register用户登录界面,讲注册的信息存入到数据库,TestLogin即登录界面检查密码是否与数据库一致,一致的话进入,并且在主页面可以显示用户登录信息,这里有个实验报告作参考,代码自己体会
代码片段和文件信息
package zhaoli;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegisterServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public RegisterServlet() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts “destroy“ string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
doPost(requestresponse);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
Connection cn = null;
Statement st = null;
String url = “jdbc:sqlserver://localhost;database=Users;User=sa;password=mis_123“;
try {
cn = DriverManager.getConnection(url);
st = cn.createStatement();
String userName = new String(request.getParameter(“username“).getBytes(“iso-8859-1“)“utf-8“);
String password = new String(request.getParameter(“password“).getBytes(“iso-8859-1“)“utf-8“);
String realname = new String(request.getParameter(“realname“).getBytes(“iso-8859-1“)“utf-8“);
String gender = new String(request.getParameter(“gender“).getBytes(“iso-8859-1“)“utf-8“);
String email = new String(request.getParameter(“email“).getBytes(“iso-8859-1“)“utf-8“);
String sql = “insert into Users values(‘“
+ userName + “‘‘“ + password + “‘‘“ + realname +“‘‘“ + gender +“‘‘“
+ email +“‘)“;
st.executeUpdate(sql);
System.out.println(“OK“);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
finally{
if (st!=null) try {st.close();} catch (SQLException e) {}
if (cn!=null) try {cn.close();} catch (SQLException e) {}
}
response.setContentType(“text/html“);
PrintWriter out = response.getWriter();
out.println(“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 599 2011-04-14 20:33 用户登录\Register\.classpath
文件 297 2011-04-19 15:16 用户登录\Register\.myme
....... 1751 2011-04-14 19:51 用户登录\Register\.project
....... 500 2010-03-29 09:18 用户登录\Register\.settings\.jsdtscope
....... 395 2011-04-14 19:51 用户登录\Register\.settings\org.eclipse.jdt.core.prefs
....... 462 2011-04-14 19:51 用户登录\Register\.settings\org.eclipse.wst.common.component
....... 252 2011-04-14 19:51 用户登录\Register\.settings\org.eclipse.wst.common.project.facet.core.xm
....... 49 2011-04-14 19:51 用户登录\Register\.settings\org.eclipse.wst.jsdt.ui.superType.container
....... 6 2011-04-14 19:51 用户登录\Register\.settings\org.eclipse.wst.jsdt.ui.superType.name
....... 3536 2011-04-14 21:21 用户登录\Register\src\zhaoli\RegisterServlet.java
....... 834 2010-03-29 09:18 用户登录\Register\WebRoot\index.jsp
....... 36 2010-03-29 09:18 用户登录\Register\WebRoot\me
....... 1356 2011-03-28 11:15 用户登录\Register\WebRoot\MyHtml.html
文件 3419 2011-04-19 15:16 用户登录\Register\WebRoot\WEB-INF\classes\zhaoli\RegisterServlet.class
....... 829 2011-03-28 10:38 用户登录\Register\WebRoot\WEB-INF\web.xm
....... 599 2011-04-14 14:21 用户登录\TestLogin\.classpath
文件 300 2011-04-19 15:16 用户登录\TestLogin\.myme
....... 1752 2011-03-31 10:17 用户登录\TestLogin\.project
....... 493 2011-03-31 09:34 用户登录\TestLogin\.settings\.jsdtscope
....... 395 2011-03-31 09:34 用户登录\TestLogin\.settings\org.eclipse.jdt.core.prefs
....... 465 2011-03-31 09:34 用户登录\TestLogin\.settings\org.eclipse.wst.common.component
....... 252 2011-03-31 09:35 用户登录\TestLogin\.settings\org.eclipse.wst.common.project.facet.core.xm
....... 49 2011-03-31 09:35 用户登录\TestLogin\.settings\org.eclipse.wst.jsdt.ui.superType.container
....... 6 2011-03-31 09:35 用户登录\TestLogin\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 2521 2011-04-19 16:19 用户登录\TestLogin\src\com\song\IdentityServlet.java
....... 3297 2011-04-17 14:05 用户登录\TestLogin\src\com\song\LoginServlet.java
....... 1868 2011-04-17 14:05 用户登录\TestLogin\src\com\song\LogoutServlet.java
文件 2837 2011-04-19 15:50 用户登录\TestLogin\src\com\song\MainServlet.java
文件 3738 2011-04-19 15:48 用户登录\TestLogin\src\com\song\ShowServlet.java
....... 848 2011-03-31 09:53 用户登录\TestLogin\WebRoot\error.jsp
............此处省略33个文件信息
相关资源
- 用户同一时段不能重复登录类似QQMy
- 数据库SQL的大作业
- WebQQ(myeclipse+sql server+web)
- 数据库原理与SQL Server2005应用教程
- 在线购物系统Myeclipse+Tomcat+MysqL
- 组态王与SQLServer的交互
- 银行管理系统MyEclipse Hibernate Struts M
- 用户信息管理系统
- 电子商务网站+sqlserver
- 医院预约挂号系统代码 mysql+myeclipse
- Eclipse+sql做的用户登录注册系统
- 非常适合个人项目 商城购物系统 W
- myeclipse+mysql商城购物车注册
- 类似豆瓣的读书讨论系统
- MVC图书管理系统mysql+tomcat+myeclipse
- Shape与Sqlite数据转换
- 串口接收与SQL数据库存取
- 新闻网站用户端,管理端
- Myeclipsestruts2实现增删改查+mysql数据库
- 在线选课系统myeclipse+mysql+tomcat
- 图书馆管理系统mysql+MyEclipse
- web通过myeclipse,mysql实现数据库的连接
- 网上书店系统用mysql和myeclipse编写
- 用myeclipse作的第一个hibernate连接mysq
- myeclipse(struts2+spring3+hibernate3)案例附
- mysql+MyEclipse编写的家庭理财工具代码
- 酒店管理系统myeclipse+ oracle +tomcat
- Myeclipse8.5+SQLServer08员工信息管理系统
- MyEclipse+MySql日程管理系统
- Myeclipse新闻发布系统
评论
共有 条评论