-
大小: 2.06MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-09-04
- 语言: Java
- 标签:
资源简介
自己最近学习写成的代码!jsp,Mysql,servlet,验证码为一体的简单的用户登陆验证!一定可以用!
代码片段和文件信息
package com.demo.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
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;
/**
* Servlet implementation class login
*/
@WebServlet(“/login“)
public class login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public login() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
// TODO Auto-generated method stub
doPost(request response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
// TODO Auto-generated method stub
//编码格式的改变
request.setCharacterEncoding(“UTF-8“);
response.setCharacterEncoding(“UTF-8“);
//获取用户名,密码验证码输入内容
String uname = request.getParameter(“uname“);
String pword = request.getParameter(“pword“);
String check = request.getParameter(“check“);
System.out.println(uname);
System.out.println(pword);
System.out.println(check);
//获取验证码
// response.setContentType(“text/html“);
// PrintWriter out = response.getWriter();
//通过request得到session
String code = request.getSession().getAttribute(“code“).toString();
System.out.println(code);
//连接数据库
ResultSet rs = null;
Statement stmt = null;
RequestDispatcher dispatcher;
Connection conn = null;
try {
//1.驱动加载
Class.forName(“com.mysql.jdbc.Driver“);
//2.建立连接
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/mytest“ “root“ “123456“);
//3.建立statement对象
stmt = conn.createStatement();
System.out.println(“连接数据库成功!“);
} catch (ClassNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//查询mysql中的数据信息
//将输入的密码转换成MD5加密:
try {
MessageDigest md = MessageDigest.getInstance(“MD5“);
md.update(pword.getBytes());//update处理
byte [] encryContext = md.digest();//调用该方法完成计算
int i;
StringBuffer buf = new StringBuffer(““);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-02-03 18:19 demo1\
文件 819 2016-01-29 14:47 demo1\.classpath
文件 1038 2016-01-29 14:12 demo1\.project
目录 0 2016-02-03 18:19 demo1\.settings\
文件 503 2016-01-26 14:56 demo1\.settings\.jsdtscope
目录 0 2016-02-03 18:19 demo1\.settings\.svn\
文件 77 2016-01-29 14:13 demo1\.settings\.svn\dir-wcprops
文件 0 2016-01-29 14:13 demo1\.settings\.svn\empty-file
文件 2092 2016-01-29 14:13 demo1\.settings\.svn\entries
文件 2 2016-01-29 14:13 demo1\.settings\.svn\format
目录 0 2016-01-29 14:13 demo1\.settings\.svn\prop-ba
目录 0 2016-01-29 14:13 demo1\.settings\.svn\props\
文件 120 2016-01-29 14:13 demo1\.settings\.svn\README.txt
目录 0 2016-02-03 18:19 demo1\.settings\.svn\text-ba
文件 503 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 88 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 364 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 467 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 305 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 49 2016-01-29 14:13 demo1\.settings\.svn\text-ba
文件 6 2016-01-29 14:13 demo1\.settings\.svn\text-ba
目录 0 2016-02-03 18:19 demo1\.settings\.svn\tmp\
目录 0 2016-01-29 14:13 demo1\.settings\.svn\tmp\prop-ba
目录 0 2016-01-29 14:13 demo1\.settings\.svn\tmp\props\
目录 0 2016-01-29 14:13 demo1\.settings\.svn\tmp\text-ba
目录 0 2016-01-29 14:13 demo1\.settings\.svn\tmp\wcprops\
目录 0 2016-02-03 18:19 demo1\.settings\.svn\wcprops\
文件 88 2016-01-29 14:13 demo1\.settings\.svn\wcprops\.jsdtscope.svn-work
文件 110 2016-01-29 14:13 demo1\.settings\.svn\wcprops\org.eclipse.core.resources.prefs.svn-work
文件 104 2016-01-29 14:13 demo1\.settings\.svn\wcprops\org.eclipse.jdt.core.prefs.svn-work
文件 110 2016-01-29 14:13 demo1\.settings\.svn\wcprops\org.eclipse.wst.common.component.svn-work
............此处省略210个文件信息
- 上一篇:jsp3实习跟踪管理系统
- 下一篇:Android 酒店预订系统源码.rar
评论
共有 条评论