Improve configuration information
Improvement 1; Modify the Welcome page configuration information in Web. XML and move index.jsp to the JSP folder
<!--Project Welcome page, Home--
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
Improvement 2: Insert the following code in the Spmvc-servlet.xml file
1 <!--all resources in spring are treated as beans. -2 <BeanID= "Simpleurlhandlermapping"3 class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">4 < Propertyname= "Mappings">5 <Props>6 <propKey= "/my.do">MyControl</prop>7 <propKey= "/login.do">Logincontrol</prop>8 </Props>9 </ Property>Ten </Bean> One <!--prefix and suffix the JSP pages that are accessed - A <BeanID= "Viewresolver" - class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> - < Propertyname= "prefix"value= "/jsp/" /> the < Propertyname= "suffix"value= ". jsp" /> - </Bean> - - <!--Description: The my.do request will be processed by the bean named MyControl. - + <BeanID= "MyControl"class= "Com.test.MyController"></Bean> - <BeanID= "Logincontrol"class= "Com.test.LoginControl"></Bean>
Improvement 3: Change Mycontroller.java file
Written by: Logincontrol.java file
1 Packagecom.test;2 3 Importjavax.servlet.http.HttpServletRequest;4 ImportJavax.servlet.http.HttpServletResponse;5 6 ImportOrg.springframework.web.servlet.ModelAndView;7 ImportOrg.springframework.web.servlet.mvc.Controller;8 9 Public classLogincontrolImplementscontroller{Ten One @Override A PublicModelandview HandleRequest (httpservletrequest arg0, HttpServletResponse arg1)throwsException { - //TODO auto-generated Method Stub -Modelandview mv =NewModelandview ("Login"); theMv.addobject ("Work", "Dfdsfs"); - returnMV; - } - +}
Improvement 4. Writing login.jsp files
1 <%@ Pagelanguage= "Java"Import= "java.util.*"pageencoding= "UTF-8"%>2 <%3 StringPath= Request.getcontextpath ();4 String BasePath= Request.getscheme ()+ "://" + request.getservername () + ":" + request.getserverport ()5 + path + "/";6 %>7 8 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en">9 <HTML>Ten <Head> One <Basehref= "<%=basePath%>"> A - <title>My JSP ' login.jsp ' starting page</title> - the <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" > A - at - </Head> - - <Body> - <formAction= "POST"Method= "Get"> -First Name:<BR> <inputtype= "text"name= "FirstName"> <BR> inLast Name:<BR> <inputtype= "text"name= "LastName"> - to </form> + ${or something to work with. - the </Body> * </HTML>
5. Questions about accessing the webpage
1. Start the project
2. Open the browser
Open the first page of the project;
<a href= "http://localhost:8080/my_web_spring/jsp/login.jsp" > Login screen </a>
3. Enter my.do after the browser address bar
Returns information in a Java file
4. Click on the link to jump to the login screen
5.
Spring MVC Framework (introductory article)-2