Direct to dry goods based on spring MVC has a certain basis
First Web.xml as we all know spring MVC was developed based on the servlet
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi: schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id= " webapp_id "version=" 3.1 ">
<display-name>spring-mvc</display-name>
<!--Configure servlet request blocking-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/applicationContext-mvc.xml</param-value><!--Read configuration file-->
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
The Applicationcontext-mvc.xml configuration file is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<beans
Xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx= "Http://www.springframework.org/schema/tx"
xmlns:context= "Http://www.springframework.org/schema/context"
Xmlns:mvc= "Http://www.springframework.org/schema/mvc"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
Http://www.springframework.org/schema/tx
Http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-3.2.xsd
Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd ">
<!--automatically scanned package names all of my controller classes are under Controllers's bag-->
<context:component-scan base-package= "Controllers"/>
<!--default annotation mapping support, autoenrollment defaultannotationhandlermapping and Annotationmethodhandleradapter-->
<mvc:annotation-driven/>
<!--view Interpretation class-->
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/"/> <!--Find in full directory-->
<property name= "suffix" value= ". jsp"/> <!--find. jsp files in the full directory-->
<property name= "Viewclass" value= "Org.springframework.web.servlet.view.JstlView"/>
</bean>
</beans>
The TestController classes are as follows:
Package controllers;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.ui.ModelMap;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestParam;
Import Azj.user;
@Controller
@RequestMapping ("/admin")
public class TestController {
Login.do Request
@RequestMapping ("/login")//Get page Values page properties are username with the Name property and can be passed by object
public string AddUser (Modelmap MP, @RequestParam ("username") string name*/) {
System.out.println ("com---------");
Pass Value
Mp.addattribute ("U", u);
Rendered pages
return "/welcome";
}
}