Spring MVC Primary Configuration sample __spring

Source: Internet
Author: User

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";

}


}


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.