Spring MVC Framework (introductory article)-2

Source: Internet
Author: User

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

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.