用response输出一个验证码

package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FirstServlet extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public FirstServlet() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.execute(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.execute(request,response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void execute(HttpServletRequest request,HttpServletResponse response)
        throws ServletException,IOException
    {
        this.log("则行doget方法");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        String requestURI=request.getRequestURI();
        String method=request.getMethod();
        String param=request.getParameter("param");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
        out.println("  <BODY>");
        out.println(method+"方式访问该页面。取到的para参数是"+param+"<br/>");
        out.println("<form action=‘"+requestURI+"‘method=‘post‘><input type=‘text‘ name=‘qqq‘ value=‘param string‘><input type=‘submit‘ value=‘用post方式查询"+requestURI+"‘></form>");
        out.println("<script>document.write(‘本页面最后更新时间‘+document.lastModified);</script>");
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
    public void init() throws ServletException {
        // Put your code here
    }

}

时间: 2024-10-07 13:45:07

用response输出一个验证码的相关文章

自己实现一个验证码功能

用Servlet技术实现验证码功能,(画出一个验证码) 公司中一般用写好的验证码(jar包),很少使用自己去画验证码 . package chensi.com; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import j

输出随机验证码图片

1 /** 2 * //输出随机验证码图片:CAPTCHA图像 3 */ 4 public class ServletDemo1 extends HttpServlet { 5 private static final long serialVersionUID = 1L; 6 7 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOEx

Response输出excel设置文本样式

在网上查了些Response导出excel然后设置样式的方法,发现没有一个可行的于是开始自己研究, 发现可以通过输出样式的方式进行配置,我要设置的是全文本格式在excel样式是这样的mso-number-format:"\@" 于是我对Response输出进行了完善 Response.Clear(); Response.BufferOutput = true; string style = "<style> td{ mso-number-format:\"

再学IHanlder 类----------------关于Asp.net与iis原理网上看博客收获写一个验证码用一般处理程序记的好长时间前就写过不过现在再看有点不一样的感觉

建一个web网站 新建一般处理程序直接贴代码: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.SessionState;using System.Drawing;using System.Text;using System.Drawing.Imaging; namespace HandlerStudy{    /// <summary>    /

JavaScript面试题:重复输出一个给定的字符串

面试题 重复输出一个给定的字符串(str第一个参数)n 次 (num第二个参数),如果第二个参数num不是正数的时候,返回空字符串. function repeatStringNumTimes(str, num) { return str; } repeatStringNumTimes("abc", 3); 提供测试情况: repeatStringNumTimes("*", 3) //应该返回 "***". repeatStringNumTime

【输出一个整数的二进制存储形式】

// 输出一个整数的二进制存储形式void putBinary(int n){ int bits = sizeof(n) * 8; while (bits-->0) { printf("%d", n>>bits&1); if (bits%4==0) printf(" "); } printf("\n");}

For循环输出一个表格

<!-- 作者:郑伟钊 时间:2017-01-16 描述:通过一个循环的嵌套输出一个表格 --> <?php header("Content-type:text/html;charset=utf-8"); //如果不加这一行,输出的中文会乱码 echo '<table border="1px" width="800" align="center">' ; //设置表格的边框为1px,宽度为800(

c语言:输出一个数组,判断是否存在问题,若有,请找出问题并改正

输出一个数组,判断是否存在问题,若有,请找出问题并改正 程序: #include <stdio.h> int main() { int i, a[5] ; for (i = 0; i <=5; i++) { a[i] = 0; } for (i = 0; i <5; i++) { printf("%d\n", a[i]); } return 0; } 结果:出现崩溃 分析:循环的次数超过了数组长度 改正后程序: #include <stdio.h>

Java循环输出一个菱形与阶乘倒数

package javafirst; public class HomeWork { public static void main(String[] args){ System.out.println("输出一个菱形!"); for(int i = 0; i < 5; i ++){ for(int j = 5; j > i + 1; j--){ System.out.print(" "); } for(int k = 0; k < 2*i + 1