Springmvc combining Cx-common to realize verification code function

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/kouwoo/article/details/42675201

The configuration of the SPRINGMVC is not detailed, the code of the key place is posted here

code.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><% @taglib uri=" http://www.springframework.org/tags/form "prefix=" form " %><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Codecontroller.java

Package Net.spring.controller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Javax.servlet.http.httpsession;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.requestmethod;import Org.springframework.web.bind.annotation.requestparam;import com.cx.web.common.util.randomvalidatecode;@ Controllerpublic class Codecontroller {@RequestMapping (value = "Code", method = requestmethod.get) public String code ( HttpSession session, HttpServletRequest request) {Session.setattribute ("W", Request.getcontextpath ()); return "Code";} /** * Get Verification Code * @param response * @param request * * @RequestMapping ("im") public void validationimg (HttpServletResponse respon Se,httpservletrequest request) {Response.setcontenttype ("image/jpeg");//Set the appropriate type to tell the browser that the content of the output is a picture Response.setheader (" Pragma "," No-cache ");//Set the response header information to tell the browser not to cache this content Response.setheader (" Cache-control "," No-cache "); Response.setdateheader ("Expire", 0); Randomvalidatecode Randomvalidatecode = new Randomvalidatecode (); try {Randomvalidatecode.getrandcode (request, Response);//Output Picture method} catch (Exception e) {}}/** * determine if the captcha is correct * @param Validatecode * @param session * @return */@RequestMap Ping (value = "Validate", method = requestmethod.post) public string Validate (@RequestParam string Validatecode, HttpSession session) {//get codestring Validatec = (String) in session Session.getattribute ( Randomvalidatecode.randomcodekey); if (Validatecode = = NULL | | "". Equals (Validatecode)) {//Input verification code is empty//Todo}if (!validatec.equals (Validatecode.touppercase ())) {//input code is incorrect//TODO} return null;}}


Springmvc combining Cx-common to realize verification code function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.