是个indexs.jsp,是生成验证码的代码.
<%@ page contentType="image/jpeg" import="java.awt.*, 
java.awt.image.*,java.util.*,javax.imageio.*" %> 
<%! 
Color getRandColor(int fc,int bc) 

Random random = new Random(); 
if(fc>255) fc=255; 
if(bc>255) bc=255; 
int r=fc+random.nextInt(bc-fc); 
int g=fc+random.nextInt(bc-fc); 
int b=fc+random.nextInt(bc-fc); 
return new Color(r,g,b); 

%> 
<% response.setHeader("Pragma","No-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.setDateHeader("Expires", 0); 
int width=60, height=20; 
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); 
Random random = new Random(); 
g.setColor(getRandColor(200,250)); 
g.fillRect(0, 0, width, height); 
g.setFont(new Font("Times New Roman",Font.PLAIN,18)); 
g.setColor(getRandColor(160,200)); 
for (int i=0;i<155;i++) 

int x = random.nextInt(width); 
int y = random.nextInt(height); 
int xl = random.nextInt(12); 
int yl = random.nextInt(12); 
g.drawLine(x,y,x+xl,y+yl); 
} String sRand=""; 
for (int i=0;i<4;i++){ 
String rand=String.valueOf(random.nextInt(10)); 
sRand+=rand; 
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110))); 
g.drawString(rand,13*i+6,16); 
} session.setAttribute("rand",sRand); 
g.dispose(); 
ImageIO.write(image, "JPEG",response.getOutputStream() ); 
%> ----------------------------------------------------------------------------------------------------------------------------------
这个是输入的验证是否正确 validate.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> 
<% 
String rand = (String)session.getAttribute("rand"); 
String input = request.getParameter("checkcode"); 
if(rand.equals(input)){ 
out.print("<script>alert('验证通过!');</script>"); 
} else{ 
out.print("<script>alert('请输入正确的验证码!');location.href='login.jsp';</script>"); 

%> 
-----------------------------------------------------------------------------------------------------------------------------------这个显示验证码的页面 index.jsp<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"><html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Page-Exit" content="revealTrans(Duration=3,Transition=5)">
    </head>
       <body>
    
   <form action="as.html" method="POST" name="login">
   <table border="1">
       <tr>
        <td>
           验证码: 
        </td>
        <td>
            <input type="text" name="checkcode" />
            <img alt="code..." name="randImage" id="randImage" src="indexs.jsp" width="60" height="20" border="1" align="absmiddle" />
        </td>
    </tr>
    <tr>
      <td><input type="submit" value="Submit" /></td>
      <td><input type="reset" value="Reset" /></td>
    </tr>
  </table>
              
     </form>
           
    </body>
</html>
------------------------------------------------------------------------------------------------------------------------------------
上面能成功跳转。
------------------------------------------------------------------------------------------------------------------------------------
我试了好久都没有找到,用JS在index.jsp进行验证码验证,然后在跳转到成功页面。可是试了好久都找不到。各位帮帮忙,我刚学的JSP。