1, the second way to configure the processor
<!--Configure Handler - <BeanID= "/firstcontroller"class= "Com.songyan.controller.FirstController"></Bean> <BeanID= "Logoon"class= "Com.songyan.controller.LoginHandler"> </Bean> <!--Mapper - <Beanclass= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <!--Mapper 2 - <Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < Propertyname= "Mappings"> <Props> <propKey= "Login1">Logoon</prop> </Props> </ Property> </Bean> <!--Adapter - <Beanclass= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <!--Adapter 2 - <Beanclass= "Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" /> <!--Parser - <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"></ Property> < Propertyname= "prefix"value= "web-inf/jsp/"></ Property> < Propertyname= "suffix"value= ". jsp"></ Property> </Bean>
2,loginhandler
PackageCom.songyan.controller;Importjava.io.IOException;Importjavax.servlet.ServletException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.web.HttpRequestHandler; Public classLoginhandlerImplementsHttprequesthandler { Public voidHandleRequest (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {String username=request.getparameter ("username"); String Password=request.getparameter ("Password"); Request.setattribute ("Username", username); Request.setattribute ("Password", password); Request.getrequestdispatcher ("Login.jsp"). Forward (request, response); }}
3,login.jsp
<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML> <Head> <Basehref= "<%=basePath%>"> <title>My JSP ' login.jsp ' starting page</title> <Metahttp-equiv= "Pragma"content= "No-cache"> <Metahttp-equiv= "Cache-control"content= "No-cache"> <Metahttp-equiv= "Expires"content= "0"> <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3"> <Metahttp-equiv= "description"content= "This is my page"> <!--<link rel= "stylesheet" type= "Text/css " href= "Styles.css" > - </Head> <Body> <formAction= "Login1"Method= "POST">User name:<inputtype= "text"name= "username" >${username}<BR><BR>Password:<inputtype= "text"name= "Password">${password}<BR><BR> <inputtype= "Submit"value= "Login"> </form> </Body></HTML>
4, Process
(1) Enter the URL to access in the browser (login.jsp)---> Page jump to login.jsp page
(2) After populating the data on the login.jsp page, submit the parameter settings via action (login1)
(3) The submitted request is blocked by the front-end controller, locate the Springmvc-servlet.xml file by setting the location of the configuration file
(4) The front controller invokes the processor mapper and finds the login1 (corresponding to the key in the prop) based on the parameters in the action
(5) corresponds to value according to the matching key value (here is the Logoon)
(6) Find the corresponding handler according to value
(7) Call handler, jump to login.jsp page due to the jump statement in handler
Spring Starter Program-Front Controller Configurator