JSP实现验证码
验证码的实现分为JSP页面和Java类Servlet两部分:
JSP页面:
<!DOCTYPE html>
<html>
<head>
<title>loginForm.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="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<h3>带有验证码的登陆页面</h3>
<form method="post" action="login.yan" >
用户名:<input type="text" name="usreName" size="10"><br><br/>
密 码:<input type="password" name="password" size="10"><br><br>
验证码:<input type="text" name="userNum" size="4"><img src="loginForm"/><br/><br/>
<input type="submit" value="提交">
</form>
</body>
</html>
Java类:
package com.csdn.session;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class loginForm extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
private static int WIDTH = 80;
private static int HEIGHT = 20;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out=response.getOutputStream();
//PrintWriter out = response.getWriter();
相关新闻>>
- 发表评论
-
- 最新评论 更多>>