码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC框架搭建

时间:2018-06-05 17:01:00      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:ann   运行   its   uri   complete   tps   hand   cep   context   

1.导入JAR包

2.配置web.xml配置文件

  <servlet>
  	<servlet-name>SpringMVC</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>SpringMVC</servlet-name>
  	<url-pattern>/*</url-pattern>
  </servlet-mapping>

3.编写XX-servlet.xml配置文件(SpringMVC配置文件)

XX根据<servlet-name>SpringMVC</servlet-name>决定的

所以XX=SpringMVC,所以SpringMVC-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
        <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
        <bean name="/hello.action" class="com.zhangpn.Controller.MyController"></bean>
</beans> 

4.写出

com.zhangpn.Controller.MyController
package com.zhangpn.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class MyController extends AbstractController {

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		
		System.out.println("hello controller");
		
		return null;
	}
	
}

5.运行一下

六月 05, 2018 4:23:40 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/SpringMVC-servlet.xml]
六月 05, 2018 4:23:40 下午 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
信息: Mapped URL path [/hello.action] onto handler ‘/hello.action‘
六月 05, 2018 4:23:40 下午 org.springframework.web.servlet.FrameworkServlet initServletBean
信息: FrameworkServlet ‘SpringMVC‘: initialization completed in 303 ms
六月 05, 2018 4:23:40 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet with name ‘SpringMVC‘
六月 05, 2018 4:23:55 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/SpringMVC/hello] in DispatcherServlet with name ‘SpringMVC‘
hello controller

  

 

SpringMVC框架搭建

标签:ann   运行   its   uri   complete   tps   hand   cep   context   

原文地址:https://www.cnblogs.com/batj/p/9140472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!