<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) 評論(0)  編輯  收藏 所屬分類: Struts1Spring個人學習日記
    主站蜘蛛池模板: 成全在线观看免费观看大全| 国产线视频精品免费观看视频| 在线看片v免费观看视频777 | 日韩内射激情视频在线播放免费| 亚洲中文无韩国r级电影| 理论秋霞在线看免费| 亚洲第一页日韩专区| 亚洲精品视频免费| 亚洲精品美女久久777777| 在线观看片免费人成视频播放| 亚洲乳大丰满中文字幕| 秋霞人成在线观看免费视频| 亚洲AV无码成人精品区蜜桃| 日韩视频在线观看免费| 亚洲综合视频在线观看| 成人免费视频69| 亚洲s码欧洲m码吹潮| 亚洲国产天堂久久久久久| 好男人资源在线WWW免费| 亚洲av无码片在线播放| h视频在线免费看| 中文字幕在线观看亚洲日韩| 免费观看亚洲人成网站| 青青草国产免费国产是公开 | 亚洲伊人成无码综合网| 国产一级片免费看| 亚洲av成人一区二区三区| 日本免费一二区在线电影| 午夜不卡AV免费| 久久精品亚洲一区二区三区浴池| 999国内精品永久免费观看| 激情小说亚洲图片| 亚洲人成人网毛片在线播放| 亚洲一级毛片免费在线观看| 亚洲一级免费视频| 亚洲伊人色一综合网| 亚洲xxxxxx| 亚洲av第一网站久章草| 日本高清不卡aⅴ免费网站| 日本免费网站在线观看| a毛片免费全部在线播放**|