register.jsp

<%@ page contentType="text/html;charset=gb2312" %>

<script language="javascript">

function on_submit()

{

  if(form1.username.value=="")

  {

     alert("用户名不能为空,请输入用户名!");

     form1.username.focus();

     return false;

  }

  if(form1.userpassword.value=="")

  {

     alert("用户确认密码不能为空,请输入密码!");

     form1.userpassword.focus;

     return false;

  }

  if(form1.userpassname.value !=form1.userpassword.value)

  {

     alert("密码与确认密码不同");

     form1.userpassword.focus;

     return false;

  }

  if(form1.email.value.length!=0)

  {

     for(i=0;i<form1.email.value.length;i++)

       if(form1.email.value.charAt(i)=="0")

          break;

     if(i==form1.email.value.length)

     {

       alert("非法Email地址!");

       form1.email.focus();

       return false;

     }   

  }

  else

  {

    alert("请输入!Email");

    form1.email.focus();

    return false;

  }

}

</script>

<html>

<head>

<title>新用户注册</title>

</head>

<body>

<form method="post" action="servlet/accept" name="form1" onsubmit="return on_submit()">

  新用户注册<br>

  用户名(*):<input type="text" name="username" size="20"><br>

  密码(*):<input type="password" name="userpassword" size="20"><br>

  再输一次密码(*):<input type="password" name="reuserpassword" size="20"><br>

  性别:<input type="radio" value="男" checked name="sex"><input type="radio" name="sex" value="女"><br>

  出生年月:<input name="year" size="4" maxlength=4><select name="month">

     <option value="1" selected>1</option>

     <option value="2" selected>2</option>

     <option value="3" selected>3</option>

     <option value="4" selected>4</option>

     <option value="5" selected>5</option>

     <option value="6" selected>6</option>

     <option value="7" selected>7</option>

     <option value="8" selected>8</option>

     <option value="9" selected>9</option>

     <option value="10" selected>10</option>

     <option value="11" selected>11</option>

     <option value="12" selected>12</option>

     </select><input name="day" size="3" maxlength=4><br>

     电子邮箱(*):<input name="email" maxlength=28><br>

     家庭住址:<input type="text" name="address" size="20"><br>

     <input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"><br>

     </form>

     </body>

     </html>     

阅读更多

HTTP Status 404 - /jspdemo/Register.jsp

07-29

2009-7-29 11:17:36 org.apache.catalina.core.AprLifecycleListener initrn信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\MyEclipse-6.0M1\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\binrn2009-7-29 11:17:36 org.apache.coyote.http11.Http11Protocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2009-7-29 11:17:36 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 760 msrn2009-7-29 11:17:36 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2009-7-29 11:17:36 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.18rn2009-7-29 11:17:38 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts-default.xml]rn2009-7-29 11:17:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts-plugin.xml]rn2009-7-29 11:17:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts.xml]rn2009-7-29 11:17:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Loading global messages from messagern2009-7-29 11:17:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warnrn警告: No interceptor found for name = maximumSizern2009-7-29 11:17:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts-default.xml]rn2009-7-29 11:17:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Unable to locate configuration files of the name struts-plugin.xml, skippingrn2009-7-29 11:17:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts-plugin.xml]rn2009-7-29 11:17:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger inforn信息: Parsing configuration file [struts.xml]rn2009-7-29 11:17:41 org.apache.coyote.http11.Http11Protocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2009-7-29 11:17:41 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2009-7-29 11:17:41 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/46 config=nullrn2009-7-29 11:17:41 org.apache.catalina.startup.Catalina startrn信息: Server startup in 5596 ms

编写了一个注册用的register.jsp不能正常显示验证码

01-31

JSP不能显示生产的验证码图片,不知原因何在,请教,拜托了!rn生成验证码的类:ValidationCode,位置:/src/chapter6rn代码如下:rnrnpackage chapter6;rnimport java.awt.Color;rnimport java.awt.Font;rnimport java.awt.Graphics;rnimport java.awt.image.BufferedImage;rnimport java.io.IOException;rnimport java.io.OutputStream;rnimport java.io.PrintWriter;rnrnimport javax.imageio.ImageIO;rnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnimport javax.servlet.http.HttpSession;rnrnimport java.util.*;rnrnrnpublic class ValidationCode extends HttpServlet rn //用于生产验证码所需的所有字符rn private static String allChars = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";rnrn @Overridern public void service(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOException rnrn response.setContentType("text/html; charset=UTF-8");rn Random random = new Random();rn int charLength = allChars.length();rn StringBuilder validationCode = new StringBuilder();//验证码rn //设置图形的长和高rn int length = 60;rn int height = 20;rn BufferedImage img = new BufferedImage(length, height, BufferedImage.TYPE_INT_RGB);rn Graphics g = img.getGraphics();rn //设置背景颜色rn g.setColor(getColor(180,255));rn g.fillRect(0, 0, length, height);rn String[] fontNames = "Times New Roman", "Book antiqua", "Arial";//主要使用的3种字体rn //随机生成3到5个验证码rn for(int i = 0; i < 3 + random.nextInt(3); i++)rn rn g.setColor(getColor(100,180));rn g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, 20));rn char randomChar = allChars.charAt(random.nextInt(charLength));//随机取出一个字符rn g.drawString(String.valueOf(randomChar), 16*i, height);rn validationCode.append(randomChar);rn rn //获得HttpSession对象rn HttpSession session = request.getSession();rn session.setMaxInactiveInterval(5*60);//设置session 5分钟后实效rn //将验证码保存在session中,key为validation_codern session.setAttribute("validation_code", validationCode.toString());rn g.dispose();//关闭Graphics对象rn //以JPEG的格式向客户端发送验证码rn OutputStream os = response.getOutputStream();rn ImageIO.write(img, "JPEG", os); rn rn //随机获得颜色值,颜色值范围:min~max,其中max值不能超过255,min不能小于0rn private static Color getColor(int min, int max)rn rn Random random = new Random();rn if(max > 255)rn max = 255;rn if(min < 0)rn min = 0;rn int red = min + random.nextInt(max - min);rn int green = min + random.nextInt(max - min);rn int blue = min + random.nextInt(max - min);rn return new Color(red,green,blue);rn rnrnregister.jsp的代码如下:rnrn rn 注册rn rn rn rn *用户名:rn rn rn rn *密码:rn rn rn rn *请再次输入密码:rn rn rn rn *email:rn rn rn rn *验证码:rn rn rn rn rn rn rn rn rn rn rn

没有更多推荐了,返回首页