SpringMVC realize there are some cases of simple explanation

1. First import jar package

2. Create a index.jap in webContent, and then set a label a

<a href="handler/welcome1">first springmvc1  </a>

3.java project, create packages and classes in the src

@Controller
@RequestMapping("handler")
public class SpringMVCHandler {

@RequestMapping("welcome1")
public String welcome1() {
	return "success1";
}

4. Create a new file in the web Content for the view as the view layer, create a success1 on the inside, on the inside to write your hello springMVC

Here Insert Picture Description
The configuration file springmvc.xml
disposed inside view resolver:

配置扫描器
	<context:component-scan base-package="org.awen.handler"></context:component-scan>

	<!-- 配置视图解析器 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- 配置视图解析器的前缀和后缀 -->
		<property name="prefix" value="/view/"></property>
		<property name="suffix" value=".jsp"></property>

	</bean>

Inside the prefix with the file name you can set and change the.

6. web.xml configuration file

  <servlet>
  	<servlet-name>springDispatcherServlet</servlet-name>
  	
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<!-- 设置xml的 路径 -->
  		<param-value>classpath:springmvc.xml</param-value>
  	</init-param>
  	
  	<!-- 设置第一启动 -->
  	<load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
  	  	<servlet-name>springDispatcherServlet</servlet-name>
  		<url-pattern>/</url-pattern>
  </servlet-mapping>
  

7. explain something present:
Configuration springMVC Servlet carrying
this configuration, it intercepts all requests to process springMVC;

<servlet-name>springDispatcherServlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>
	<param-name>contextConfigLocation</param-name>
	<!-- 设置xml的 路径 -->
	<param-value>classpath:springmvc.xml</param-value>
</init-param>

Where:
<url-pattern>/</url-pattern>
/: all requests, attention is not / *
/ user: interception begin with / user requests
/user/abc.do: block only the request
/.action: only .action ending interception request

Guess you like

Origin blog.csdn.net/guoguozgw/article/details/91492446