首页 > Java > java教程 > 正文

PlayFramework完整实现一个APP(七)

黄舟
发布: 2016-12-23 16:42:55
原创
1560人浏览过

1.添加验证码

application Controller添加captcha()

public static void captcha() {
Images.Captcha captcha = Images.captcha();
renderBinary(captcha);
}

  

添加Route

GET     /captcha                                Application.captcha

  

访问 http://localhost:9000/captcha

212.png

验证码图片已经实现了,现在需要做的是验证输入信息与验证码一致

修改captcha()方法

public static void captcha(String id) {
Images.Captcha captcha = Images.captcha();
String code = captcha.getText("#E4EAFD");
Cache.set(id, code, "10mn");
renderBinary(captcha);
}

  

修改show()方法

public static void show(Long id) {
   Post post = Post.findById(id);
   String randomID = Codec.UUID();
   render(post, randomID);
}

weenCompany闻名企业网站系统5.3.0 繁体中英文 UTF8
weenCompany闻名企业网站系统5.3.0 繁体中英文 UTF8

weenCompany闻名企业网站系统(免费开源)是一个功能强大, 使用简单的中英文企业智能建站系统, 您只需要一些基本的计算机知识就可以利用此系统完成中小型企业网站的建设; 是低成本企业网站架设方案之首选CMS系统, 也适合建设个人网站。weenCompany闻名企业网站系统功能:1. 程序代码简洁严谨, 整个系统程序仅2M左右大小.2. 中英文双语版共用一套网站程序, 双语页面实现自由切换.3

weenCompany闻名企业网站系统5.3.0 繁体中英文 UTF8 0
查看详情 weenCompany闻名企业网站系统5.3.0 繁体中英文 UTF8

  

修改show.html页面

在Comment下方添加验证码图片,和验证控件

  <p>
       <label for="content">Your message: </label>
       <textarea name="content" id="content">${params.content}</textarea>
   </p>
   <p>
    <label for="code">Please type the code below: </label>
    <img src="@{Application.catcha(randomId)}">
    <br />
    <input type="text" name="code" id="code" size="18" value="" />
    <input type="hidden" name="randomId" value="${randomId}" />
   </p>
   <p>
       <input type="submit" value="Submit your comment" />
   </p>

  

2.验证

修改postComment 方法

public static void postComment(
Long postId,
@Required(message="Author is required") String author,
@Required(message="A message is required") String content,
@Required(message="Please type the code") String code,
String randomId) {
   Post post = Post.findById(postId);
   validation.equals(code, Cache.get(randomId)).message("Invalid code. Please type it again");
   
   if(validation.hasErrors()) {
    render("Application/show.html", post);
   }
   
   post.addComment(author, content);    Flash.success("Thanks for posting %s", author);
   Cache.delete(randomId);
   show(postId);
}

  

修改show.html页面

  #{ifErrors}
       <p class="error">
           ${errors[0]}
       </p>
   #{/ifErrors}

 

 以上就是PlayFramework完整实现一个APP(七)的内容,更多相关内容请关注PHP中文网(www.php.cn)! 

相关标签:
app
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号