<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 閱讀(1043) 評論(0)  編輯  收藏 所屬分類: Struts1Spring個人學習日記
    主站蜘蛛池模板: 精品国产免费一区二区三区| 免费人成黄页在线观看日本| 亚洲精品无码av天堂| 中文字幕无码免费久久| 亚洲天堂一区在线| 一级毛片直播亚洲| 24小时日本韩国高清免费| 亚洲av永久无码精品网址| 亚洲V无码一区二区三区四区观看 亚洲αv久久久噜噜噜噜噜 | 在线天堂免费观看.WWW| 青青免费在线视频| 亚洲视频免费观看| 亚洲人成电影网站国产精品| 久久国产免费福利永久| 国产97视频人人做人人爱免费| 亚洲毛片在线免费观看| 亚洲精品99久久久久中文字幕| 麻豆高清免费国产一区| 一级做性色a爰片久久毛片免费| 亚洲国产美女视频| 亚洲中文字幕无码久久综合网| 69成人免费视频无码专区| 久久精品乱子伦免费| 美女被爆羞羞网站在免费观看| 中文字幕亚洲综合久久| 久久久久亚洲?V成人无码| 性感美女视频免费网站午夜| 久久久精品免费国产四虎| 老司机午夜性生免费福利 | 亚洲国产一成久久精品国产成人综合 | 日韩成人毛片高清视频免费看| 亚洲黄色免费观看| 亚洲人成无码网站| 日本一区免费电影| 久久久久免费看黄A片APP| 在线免费观看亚洲| 免费视频一区二区| 中国好声音第二季免费播放| 国内成人精品亚洲日本语音| 亚洲第一男人天堂| 亚洲伊人精品综合在合线|