Spring MVC工程搭建

2021-06-06 00:04

阅读:688

标签:--   扫描   resolve   welcome   big   encoding   turn   控制   res   

1:引入jar包

2:配置web.xml

声明DispatchServlet,监听请求

  SpringMVCDemo01

 

    index.html

    index.htm

    /view/index.jsp

    default.html

    default.htm

    default.jsp

 

 

 

 

    springmvc

    org.springframework.web.servlet.DispatcherServlet

   

    1

 

 

    springmvc

    *.do

 

3:创建Controller:

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

@RequestMapping(value="/app")

public class LoginController{

     @RequestMapping(value="/welcome") //welcome要访问的url地址

        public String hello(){

            System.out.println("hello,springmvc");

            return "hello"; //hello是逻辑视图名,和后缀名组合一起构成视图名 /web-inf/view/hello.jsp,

        }

}

4:新建springmvc-servler.xml并配置

添加扫描路径(Controller位置)

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"

    xmlns:util="http://www.springframework.org/schema/util"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  

            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  

            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  

            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

   

   

   

   

   

   

   

        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

       

       

   

Spring MVC工程搭建

标签:--   扫描   resolve   welcome   big   encoding   turn   控制   res   

原文地址:https://www.cnblogs.com/zxzxcc/p/14618642.html


评论


亲,登录后才可以留言!