Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6514532
  • 博文数量: 915
  • 博客积分: 17977
  • 博客等级: 上将
  • 技术积分: 8846
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-26 09:59
个人简介

一个好老好老的老程序员了。

文章分类

全部博文(915)

文章存档

2022年(9)

2021年(13)

2020年(10)

2019年(40)

2018年(88)

2017年(130)

2015年(5)

2014年(12)

2013年(41)

2012年(36)

2011年(272)

2010年(1)

2009年(53)

2008年(65)

2007年(47)

2006年(81)

2005年(12)

分类: Java

2011-09-27 21:56:59

  • 看到一个ofbiz自实现的验证码代码,归案备用

 

Java代码 复制代码 收藏代码
  1. Login.flt中   
  2.   
  3.   
  4. 2 border=0 src="<@ofbizUrl>/CreateImage?Image=${encryRandom}&Rgb=255|0|0" title="验证码图片">

      
  5.   
  6. <#assign random = Static["org.ofbiz.webapp.control.Picture"].getRandom()>   
  7. <#assign encryRandom = Static["org.ofbiz.webapp.control.Picture"].manage(random)>   
  8.   
  9.   
  10. controller.xml文件中   
  11.   
  12.   
  13. "CreateImage">   
  14. "java" path="org.ofbiz.webapp.control.CreateImage" invoke="make"/>   
  15. "success" type="none"/>   
  16. "error" type="none"/>   
  17.   
  18.   
  19. LoginWorker.java 类中的login方法:   
  20.   
  21. String attach = null;   
  22. String get_attach = null;   
  23. if (attach == null)   
  24. attach = request.getParameter("attach");   
  25. if (get_attach == null)   
  26. get_attach = request.getParameter("get_attach");   
  27. if (get_attach == null) {   
  28. String errMsg = "系统错误,请再次登录!";   
  29. request.setAttribute("_ERROR_MESSAGE_", errMsg);   
  30. return "error";   
  31. }   
  32. String tmp = Picture.discrypt(get_attach);   
  33. if (!attach.equals(tmp)) {   
  34. String errMsg = "请输入正确的验证码!";   
  35. request.setAttribute("_ERROR_MESSAGE_", errMsg);   
  36. return "error";   
  37. }   
  38.   
  39. 因此在login.flt 中:   
  40. <#assign attach = Static["org.ofbiz.webapp.control.Picture"].discrypt(encryRandom)>   
  41. "text" class="inputBox" name="attach" value="${attach}" size="4"/>  
阅读(1011) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~