`

ofbiz的验证码实现

XML 
阅读更多
  • 看到一个ofbiz自实现的验证码代码,归案备用

 

Login.flt中


<img align=absbottom vspace=2 border=0 src="<@ofbizUrl>/CreateImage?Image=${encryRandom}&Rgb=255|0|0</@ofbizUrl>" title="验证码图片"></p>

<#assign random = Static["org.ofbiz.webapp.control.Picture"].getRandom()>
<#assign encryRandom = Static["org.ofbiz.webapp.control.Picture"].manage(random)>


controller.xml文件中

<!--pht-->
<request-map uri="CreateImage">
<event type="java" path="org.ofbiz.webapp.control.CreateImage" invoke="make"/>
<response name="success" type="none"/>
<response name="error" type="none"/>
</request-map>

LoginWorker.java 类中的login方法:

String attach = null;
String get_attach = null;
if (attach == null)
attach = request.getParameter("attach");
if (get_attach == null)
get_attach = request.getParameter("get_attach");
if (get_attach == null) {
String errMsg = "系统错误,请再次登录!";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
String tmp = Picture.discrypt(get_attach);
if (!attach.equals(tmp)) {
String errMsg = "请输入正确的验证码!";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

因此在login.flt 中:
<#assign attach = Static["org.ofbiz.webapp.control.Picture"].discrypt(encryRandom)>
<input type="text" class="inputBox" name="attach" value="${attach}" size="4"/>
 
分享到:
评论
1 楼 sspoo 2010-09-27  
整理的很详细关中中……

相关推荐

Global site tag (gtag.js) - Google Analytics