JFinal CaptchaRender的简单使用

原创
2012/07/06 10:49
阅读数 4.4K

稍微修改了下jfinal官方demo的代码,用了下验证码

效果图:


 CommonController.java

package com.demo.common;

import com.jfinal.core.Controller;
import com.jfinal.lib.captcha.CaptchaRender;

/**
 * CommonController
 */
public class CommonController extends Controller {

	private static final String RANDOM_CODE_KEY = "1";

	public void index() {
		render("/common/login.jsp");
	}

	public void login() {
		String inputRandomCode = getPara("inputRandomCode");
		boolean loginSuccess = CaptchaRender.validate(this, inputRandomCode, RANDOM_CODE_KEY);
		if (loginSuccess) {
			render("/common/index.jsp");
		}else{
			index();
		}
	}

	public void img() {
		CaptchaRender img = new CaptchaRender(RANDOM_CODE_KEY);
		render(img);

	}
}

login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/css/manage.css" media="screen" rel="stylesheet"
	type="text/css" />
<script src="/js/jquery-1.4.4.min.js" type="text/javascript"></script>
</head>
<body>
	<div class="manage_container">
		<div class="manage_head">
			<div class="manage_logo">
				<a href="http://code.google.com/p/jfinal" target="_blank">JFinal
					web framework</a>
			</div>
			<div id="nav">
				<ul>
				</ul>
			</div>
		</div>
		<div class="main">
			<h1>JFinal Demo 项目首页</h1>
			<div class="table_box">
			<form action="login" method="post">
				<img src="img" alt="" />
				<input name="inputRandomCode"/>
				<input  type="submit" value="登录"/>
			</form>
			</div>
		</div>
	</div>
</body>
</html>
展开阅读全文
加载中
点击加入讨论🔥(13) 发布并加入讨论🔥
打赏
13 评论
12 收藏
3
分享
返回顶部
顶部