栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

基于XML的Hello

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于XML的Hello

今天学习一下SpringMVC~~~~~

1、添加pom依赖

xml
    
        
        
            org.springframework
            spring-context
            5.2.3.RELEASE
        
        
        
            org.springframework
            spring-web
            5.2.3.RELEASE
        
        
        
            org.springframework
            spring-webmvc
            5.2.3.RELEASE
        
    

 2、编写web.xml文件



    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:applicationContext.xml
        
    
    
    
        springmvc
        
        /
    

 3、编写springmvc需要的spring配置文件,applicationContext.xml




    
    
    
    

    
    
        
        
        
        
    

    

 4、HelloController.java

package com.hello.controller;


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

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

public class HelloController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        //创建模型和视图对象
        ModelAndView mv = new ModelAndView();
        //将需要的值传递到model中
        mv.addObject("msg","helloSpringMVC");
        //设置要跳转的视图,
        mv.setViewName("hello");
        return mv;
    }
}

5、创建hello.jsp页面 

jsp
<%--
  Created by IntelliJ IDEA.
  User: root
  Date: 2020/3/5
  Time: 20:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


${msg}


6、配置tomcat,发送请求

http://localhost:8080/hello

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/842546.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号