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