網上搜尋了一下;風格都太簡單;
逛了下apache;發現有個開原的項目:
Jakarta Project: Image Tag library
非常好,下載下來一是;不錯;
JSP代碼如下:
<%
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
%>
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@ taglib uri="http://com.sourceware.com/taglibs/image-1.0" prefix="img" %>
<%
int num = (int) java.lang.Math.round(java.lang.Math.random() * 8999);
String sRand = "" + (1000 +num);
session.setAttribute("userInfo.authcode",sRand);
%>
<img:image src="http://images.cnblogs.com/auth.jpg" refresh="true">
<img:text text="<%=sRand.substring(0,1)%>" x="7" y="-1" font="Times New Roman" bold="false" size="22" color="0x993399" italic="true" />
<img:text text="<%=sRand.substring(1,2)%>" x="17" y="-1" font="Times New Roman" bold="false" size="22" color="0x660033" italic="false" />
<img:text text="<%=sRand.substring(2,3)%>" x="27" y="-1" font="Times New Roman" bold="true" size="18" color="0xcc3366" italic="true" />
<img:text text="<%=sRand.substring(3,4)%>" x="37" y="-1" font="Times New Roman" bold="false" size="22" color="0x990099" italic="false" />
<%if(num<4500){%>
<img:grayscale brightness="90" />
<%}%>
</img:image>
<!-- Times New Roman -->
不過,這個標籤用來做驗證碼圖片有個問題;如果返回登陸頁面;驗證碼圖片不會更新;
檢查原因發現org.apache.taglibs.image.ImageSevlet 類沒有設定:
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
修改他的代碼;重新部署;一切ok;
驗證碼圖片終於可以定製了;想什麼風格就什麼風格;自己說了算了;