JSP无刷新验证码
此实现共分三个文件,即:CreatImage.java 生成图像流的类,提供用于生成图片流的方法;images.jsp 图片包装,用于将图片加入到response输出流中;login.jsp 调用前面的jsp,显示验证码。
CreatImage.java 类:
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.Graphics;
6 import java.awt.Image;
7 import java.awt.image.BufferedImage;
8 import java.util.Random;
9
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 import javax.servlet.http.HttpSession;
13
14 public class CreatImage{
15
16 private static final long serialVersionUID = 1L;
17 Image image = null;
18 HttpServletRequest request = null;
19 HttpServletResponse response = null;
20
21 public CreatImage(HttpServletRequest request, HttpServletResponse response){
22 this.request = request;
23 this.response = response;
24 }
25
26 public Color getRandColor(int fc,int bc){//给定范围获得随机颜色
27 Random random = new Random();
28 if(fc>255) fc=255;
29 if(bc>255) bc=255;
30 int r=fc random.nextInt(bc-fc);
31 int g=fc random.nextInt(bc-fc);
32 int b=fc random.nextInt(bc-fc);
33 return new Color(r,g,b);
34 }
35
36 public BufferedImage creatImage(){
37
相关文档:
最基本的乱码问题
这个乱码问题是最简单的乱码问题。一般新会出现。就是页面编码不一致导致的乱码。
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=iso8859-1"%>
<html>
<head>
<title>中文问题</title>
<meta http-equiv="Co ......
二者区别是:
forward实际上是请求在服务器端跳转,请求方是感知不到这种跳转的,而sendRedirect是请求在客户端跳转(比如IE),等于再次从客户端发送了一个请求,forward情况下用户在地址栏里是看不到跳转后的地址的,sendRedirect则可以看到新的请求地址。 ......
<%
int a =1;
out.println("<input type='checkbox' value='"+a+"'>");
%>
<%int b =1 ;%>
<i ......
一、文件下载及版本
apache-tomcat-6.0.20.exe
jdk-6u2-windows-i586-p.exe
二、安装及环境变量设置
软件安装后,需要配置环境变量。新建JAVA_HOME, CATALINA_HOME, classpath,修改path:
classpath = ".;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\lib\servlet-api.jar"
path += ";%JAVA_ ......