国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

PlayFramework完整實現(xiàn)一個APP(七)

2019-11-14 15:15:19
字體:
供稿:網(wǎng)友

 

1.添加驗證碼

application Controller添加captcha()

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

  

添加Route

GET     /captcha                                Application.captcha

  

訪問 http://localhost:9000/captcha

驗證碼圖片已經(jīng)實現(xiàn)了,現(xiàn)在需要做的是驗證輸入信息與驗證碼一致

修改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);}

  

修改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}

 

 

 

 

 

..


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 长寿区| 永嘉县| 博湖县| 西乌珠穆沁旗| 荣昌县| 平原县| 定州市| 棋牌| 吉安市| 南岸区| 福安市| 正蓝旗| 临汾市| 昌乐县| 宿松县| 贡觉县| 汝州市| 汾阳市| 曲周县| 安徽省| 永善县| 晋城| 竹溪县| 鄂州市| 怀远县| 辛集市| 镇赉县| 桂东县| 闽侯县| 舞钢市| 游戏| 西盟| 浑源县| 封开县| 黄冈市| 太湖县| 巴南区| 利辛县| 鹰潭市| 靖远县| 洪雅县|