JSP Verification Code (Verification Code) Implementation

Source: Internet
Author: User
Tags tld
  1. Download necessary files
    1) download Jakarta-taglibs:
    Http://people.apache.org/builds/jakarta-taglibs-sandbox/nightly/
    Extract the taglibs-image.jar and place it in/WEB-INF/lib.
    Copy taglibs-image.tld to/WEB-INF/

    2) download poor man's imaging wrapper: The Image Tag uses this package.
    The http://www.mullassery.com/downloads/ can be downloaded for free after entering some necessary information
    Decompress the package and copy pmiw. jar to/WEB-INF/lib.

  2. Configure imageservlet in Web. xml
    <Context-param>
    <Param-Name> imageservletmapping </param-Name>
    <Param-value>/Gen-image </param-value>
    </Context-param>
    <Servlet>
    <Servlet-Name> imageservlet </servlet-Name>
    <Servlet-class> org. Apache. taglibs. image. imageservlet </servlet-class>
    </Servlet>
    <Servlet-mapping>
    <Servlet-Name> imageservlet </servlet-Name>
    <URL-pattern>/Gen-image/* </url-pattern>
    </Servlet-mapping>
  3. Add implementation code in the JSP page (some content refer to the http://technology.a.lunqun.com/read.php? Tid = 149894 & page = E & fpage = 1)

    1) Add <% @ taglib uri = "/WEB-INF/taglibs-image.tld" prefix = "IMG" %>

    2) Add at the top of the page
    <%
    Response. setheader ("Pragma", "No-Cache ");
    Response. setheader ("cache-control", "No-Cache ");
    Response. setdateheader ("expires", 0 );
    %>

    3) Add the following code where you want to add the verification code:
    <%
    Int num = (INT) Java. Lang. Math. Round (Java. Lang. Math. Random () * 8999 );
    String srand = "" + (1000 + num );
    Session. setattribute ("userinfo. authcode", srand );
    %>



    "x =" 7 "Y ="-1 "font =" Times New Roman "bold =" false "size =" 22 "color =" 0x993399 "italic = "True"/>
    "x =" 17 "Y ="-1 "font =" Times New Roman "bold =" false "size =" 22 "color =" 0x660033 "italic = "false"/>
    "x =" 27 "Y ="-1 "font =" Times New Roman "bold =" true "size =" 18 "color =" 0xcc3366 "italic =" true "/>
    "x =" 37 "Y ="-1 "font =" Times New Roman "bold =" false "size =" 22 "color =" 0x990099 "italic = "false"/>

    <% IF (Num <4500) {%>

    <% }%>
    </IMG: Image>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.