<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    struts-config.xml

        <form-bean name="checkForm" type="org.apache.struts.validator.DynaValidatorForm">
          <form-property name="rand" type="java.lang.String" />
        </form-bean>
        <action
          attribute="checkForm"
          input="/check/check.jsp"
          name="checkForm"
          path="/check"
          scope="request"
          validate="true"
          type="com.yourcompany.struts.action.CheckAction">
          <forward name="ok" path="/check/checkok.jsp" />
        </action>

    validation.xml

       <form name="checkForm">
            <field property="rand" depends="required">
           <arg key="checkForm.rand"/>    
           </field>  
       </form>

    spring config

    <bean name="/check" class="com.yourcompany.struts.action.CheckAction"/>

    checkAction.java

    public class CheckAction extends Action {
     /*
      * Generated Methods
      */

     /**
      * Method execute
      * @param mapping
      * @param form
      * @param request
      * @param response
      * @return ActionForward
      */
     public ActionForward execute(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) {
      DynaValidatorForm checkForm = (DynaValidatorForm) form;// TODO Auto-generated method stub
            /*HttpSession session=request.getSession();
            String strrand = (String)session.getAttribute("rand");
            session.setAttribute("rand", strrand);*/
      return mapping.findForward("ok");
     }
    }

    check.jsp

    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
     
    <html>
     <head>
      <title>JSP for DynaValidatorForm form</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
      <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
      <META HTTP-EQUIV="Expires" CONTENT="0">
     </head>
     <body>
      <html:form action="/check">
      <td><img border=0 src="check/image.jsp"></td>
      <html:text property="rand"/><html:errors property="rand"/><br/>
       <html:submit/><html:cancel/>
      </html:form>
     </body>
    </html>

     

    checkok.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>  
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
      </head>
      <body>
    <%
     String rand = (String)session.getAttribute("rand");
     String input = request.getParameter("rand");
      if (rand.equals(input)) {
    %>
    <font color=green>OK</font>
    <%
      } else {
    %>
    <font color=red>FAIL</font>
    <%
      }
    %>
      </body>
    </html>

    image.jsp

    <%@ page language="java" import="java.util.*" %>
    <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,javax.imageio.*" %>
    <%@ page import="java.io.OutputStream" %>
    <%!
    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);
    OutputStream os=response.getOutputStream();
    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",os);
    os.flush();
    os.close();
    os=null;
    response.flushBuffer();
    out.clear();
    out = pageContext.pushBody();
    %>

    posted on 2008-01-18 16:09 lzj520 閱讀(1036) 評(píng)論(0)  編輯  收藏 所屬分類: Struts1 、Spring 、個(gè)人學(xué)習(xí)日記
    主站蜘蛛池模板: 日本妇人成熟免费中文字幕| 无码永久免费AV网站| 亚洲综合小说久久另类区| 久久精品免费一区二区喷潮| 免费毛片毛片网址| 亚洲毛片在线观看| 日韩在线看片免费人成视频播放| 一级毛片a免费播放王色| 亚洲成人午夜电影| 亚洲人成人网站在线观看| **aaaaa毛片免费同男同女| WWW国产亚洲精品久久麻豆| 亚洲第一精品在线视频| 国产大片91精品免费看3| 91精品导航在线网址免费| 国产成人亚洲综合a∨| 亚洲男人天堂2017| 免费在线一级毛片| 曰曰鲁夜夜免费播放视频| 久久最新免费视频| 亚洲avav天堂av在线网爱情| 亚洲小说区图片区另类春色| 大学生高清一级毛片免费| 国产午夜成人免费看片无遮挡| 日本亚洲免费无线码 | 国产白丝无码免费视频| 亚洲国产成人va在线观看网址| 色噜噜亚洲精品中文字幕| 日韩在线不卡免费视频一区| 一级特黄aaa大片免费看| 久久夜色精品国产噜噜噜亚洲AV | 亚洲人xxx日本人18| 亚洲国产小视频精品久久久三级 | 香蕉国产在线观看免费| 亚洲中文字幕丝袜制服一区| 91手机看片国产永久免费| 一级特黄aaa大片免费看| tom影院亚洲国产一区二区| 四虎影永久在线高清免费| 免费成人福利视频| 久久九九久精品国产免费直播|