commit
72276ea357
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.5">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="jst.web"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/ojdbc14.jar"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>CheckCode</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||
<attributes>
|
||||
<attribute name="hide" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="CheckCode">
|
||||
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||
<property name="context-root" value="CheckCode"/>
|
||||
<property name="java-output-path" value="/CheckCode/build/classes"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<runtime name="Apache Tomcat v8.5"/>
|
||||
<fixed facet="java"/>
|
||||
<fixed facet="jst.web"/>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<installed facet="jst.web" version="3.0"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
</faceted-project>
|
@ -0,0 +1 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
@ -0,0 +1 @@
|
||||
Window
|
@ -0,0 +1,15 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
登陆失败!请重新登录
|
||||
<form action="login.jsp">
|
||||
<input type="submit" value="返回"><br/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
|
||||
<display-name>CheckCode</display-name>
|
||||
<welcome-file-list>
|
||||
<welcome-file>login.jsp</welcome-file>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
<welcome-file>index.htm</welcome-file>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
<welcome-file>default.html</welcome-file>
|
||||
<welcome-file>default.htm</welcome-file>
|
||||
<welcome-file>default.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
</web-app>
|
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,70 @@
|
||||
<%@page import="java.awt.image.BufferedImage"%>
|
||||
<%@page import="java.awt.*"%>
|
||||
<%@page import="java.util.*"%>
|
||||
<%@page import="javax.imageio.ImageIO" %>
|
||||
<%@ page language="java" contentType="image/jpeg; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%!
|
||||
//产生随机颜色
|
||||
public Color getColor(){
|
||||
Random ran=new Random();//random和math.random区别
|
||||
int r=ran.nextInt(256);
|
||||
int g=ran.nextInt(256);
|
||||
int b=ran.nextInt(256);
|
||||
return new Color(r,g,b);
|
||||
}
|
||||
//产生验证码的值
|
||||
public String getNum(){
|
||||
//0~8999 -> 1000~9999
|
||||
int ran=(int)(Math.random()*9000)+1000;
|
||||
return String.valueOf(ran);
|
||||
}
|
||||
|
||||
|
||||
|
||||
%>
|
||||
|
||||
<%
|
||||
|
||||
//禁止缓存 防止验证码过期
|
||||
response.setHeader("Pragma","no-cache");
|
||||
response.setHeader("Cache-Control","no-cache");
|
||||
response.setHeader("Expires","0");
|
||||
//绘制验证码图片
|
||||
BufferedImage image=new BufferedImage(80,30,BufferedImage.TYPE_INT_RGB);
|
||||
Graphics graphics=image.getGraphics();
|
||||
graphics.fillRect(0,0,80,30);
|
||||
|
||||
//绘制验证码
|
||||
graphics.setFont(new Font("seif",Font.BOLD,20));
|
||||
graphics.setColor(Color.black);
|
||||
String checkcode=getNum();
|
||||
StringBuffer sb=new StringBuffer();
|
||||
|
||||
for(int i=0;i<checkcode.length();i++){
|
||||
sb.append(checkcode.charAt(i)+" ");//获取验证码的每一位数字1 2 3 4...
|
||||
}
|
||||
//绘制验证码并调整位置
|
||||
graphics.drawString(sb.toString(), 15, 20);
|
||||
|
||||
//绘制干扰线条
|
||||
for(int i=0;i<60;i++){
|
||||
Random ran=new Random();
|
||||
|
||||
int xBegin=ran.nextInt(80);
|
||||
int yBegin=ran.nextInt(30);
|
||||
int xEnd=ran.nextInt(xBegin+10);
|
||||
int yEnd=ran.nextInt(yBegin+10);
|
||||
graphics.setColor(getColor());
|
||||
graphics.drawLine(xBegin, yBegin, xEnd, yEnd);
|
||||
}
|
||||
|
||||
//验证码的真实值用于服务器后台验证
|
||||
session.setAttribute("CHECKCODE", checkcode);
|
||||
//产生图片
|
||||
ImageIO.write(image,"jpeg",response.getOutputStream());
|
||||
out.clear();
|
||||
out=pageContext.pushBody();
|
||||
//将image加入input src中<input type="iamge" src="..."/>
|
||||
|
||||
%>
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,37 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function reloadCheckImg(){
|
||||
//alert("hahhhh");
|
||||
$("img").attr("src","img.jsp?t="+(new Date().getTime()));
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<title>验证码</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="CheckCodeServlet" method="post">
|
||||
用户名: <input type="text" name="uname"><br/>
|
||||
密码: <input type="text" name="upwd"><br/>
|
||||
<!-- -->
|
||||
验证码:
|
||||
<input type="text" name="checkcode" id="checkcodeId" size=4/>
|
||||
<!-- 验证码 -->
|
||||
<a href="javascript:reloadCheckImg();"><img src="img.jsp" /></a>
|
||||
<span id="tip"> </span><br/>
|
||||
<input type="submit" value="登录">
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,12 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
登陆成功!
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,64 @@
|
||||
package com.ytdlc.dao;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.ytdlc.entity.Login;
|
||||
|
||||
//模型层用于处理登录
|
||||
public class LoginDao {
|
||||
/**
|
||||
private final String URL="jdbc:oracle:thin:@127.0.0.1:1522:ORCL";
|
||||
private final String USERNAME="scott";
|
||||
private final String PASSWORD="tiger";
|
||||
**/
|
||||
|
||||
public static int login(Login login) {
|
||||
//boolean flag=false;
|
||||
Connection connection=null;
|
||||
PreparedStatement pstmt=null;
|
||||
ResultSet rs=null;
|
||||
int result=-1;
|
||||
try {
|
||||
Class.forName("oracle.jdbc.OracleDriver");
|
||||
connection=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:ORCL","scott","tiger");
|
||||
String sql="select count(*) from login where uname=? and upwd=?";
|
||||
pstmt=connection.prepareStatement(sql);
|
||||
pstmt.setString(1,login.getUname());
|
||||
pstmt.setString(2,login.getUpwd());
|
||||
rs=pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
result=rs.getInt(1);
|
||||
}
|
||||
if(result>0) {
|
||||
return 1;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return -1;//系统异常登陆失败
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}finally {
|
||||
try {
|
||||
if(rs!=null) rs.close();
|
||||
if(pstmt!=null) pstmt.close();
|
||||
if(connection!=null) connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.ytdlc.entity;
|
||||
|
||||
public class Login {
|
||||
private int id;
|
||||
private String uname;
|
||||
private String upwd;
|
||||
|
||||
public Login() {
|
||||
|
||||
}
|
||||
|
||||
public Login(String uname, String upwd) {
|
||||
this.uname = uname;
|
||||
this.upwd = upwd;
|
||||
}
|
||||
|
||||
public Login(int id, String uname, String upwd) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.uname = uname;
|
||||
this.upwd = upwd;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUname() {
|
||||
return uname;
|
||||
}
|
||||
public void setUname(String uname) {
|
||||
this.uname = uname;
|
||||
}
|
||||
public String getUpwd() {
|
||||
return upwd;
|
||||
}
|
||||
public void setUpwd(String upwd) {
|
||||
this.upwd = upwd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.ytdlc.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
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 com.ytdlc.dao.LoginDao;
|
||||
import com.ytdlc.entity.Login;
|
||||
|
||||
//控制器层
|
||||
@WebServlet("/CheckCodeServlet")
|
||||
public class CheckCodeServlet extends HttpServlet {
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
//login
|
||||
//获取客户端验证码
|
||||
String CheckCodeClient=request.getParameter("checkcode");
|
||||
//获取记录的真实验证码值
|
||||
String CheckCodeServer=(String) request.getSession().getAttribute("CHECKCODE");
|
||||
request.setCharacterEncoding("utf-8");
|
||||
String name=request.getParameter("uname");
|
||||
String pwd=request.getParameter("upwd");
|
||||
Login login=new Login(name,pwd);
|
||||
//LoginDao logindao=new LoginDao();
|
||||
int result=LoginDao.login(login);
|
||||
if(result>0) {
|
||||
if(CheckCodeServer.equals(CheckCodeClient)) {
|
||||
response.sendRedirect("welcome.jsp");
|
||||
}else {
|
||||
response.sendRedirect("LoginFailure.jsp");
|
||||
}
|
||||
}else {
|
||||
response.sendRedirect("LoginFailure.jsp");
|
||||
}
|
||||
/**
|
||||
String resultTip="images/wrong.jpg";
|
||||
//获取客户端验证码
|
||||
String CheckCodeClient=request.getParameter("checkcode");
|
||||
//获取记录的真实验证码值
|
||||
String CheckCodeServer=(String) request.getSession().getAttribute("CHECKCODE");
|
||||
if(CheckCodeServer.equals(CheckCodeClient)) {
|
||||
resultTip="images/right.jpg";
|
||||
}
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
PrintWriter writer=response.getWriter();//获取输出流
|
||||
writer.write(resultTip);
|
||||
writer.flush();//刷新
|
||||
writer.close();
|
||||
***/
|
||||
}
|
||||
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue