博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring MVC入门实例
阅读量:2493 次
发布时间:2019-05-11

本文共 4901 字,大约阅读时间需要 16 分钟。

1.web.xml配置

myweb
index.html
 
contextConfigLocation
classpath*:config/spring-*.xml
 
org.springframework.web.context.ContextLoaderListener
 
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/
 
 
myweb
myweb
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:config/spring-mvc.xml
1
 
springMVC
/
 

2.spring-mvc配置

 
 
 
 
 
 
 

3.HelloController类

package com.myweb.controller;    
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
@Controller
public class HelloController {
 
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public ModelAndView printWelcome() {
ModelAndView mv = new ModelAndView();
mv.setViewName("welcome");
mv.addObject("message", "you are welcome");
return mv;
}
 
}

4.welcome.jsp

<%@ page language="java" contentType="text/html; UTF-8"    
pageEncoding="ISO-8859-1"%>
Insert title here
${message}

5.eclipse的目录结构图

6.访问。输出:

you are welcome
你可能感兴趣的文章
Hive面试题干货(亲自跟着做了好几遍,会了的话对面试大有好处)
查看>>
力扣题解-230. 二叉搜索树中第K小的元素(递归方法,中序遍历解决)
查看>>
力扣题解-123. 买卖股票的最佳时机 III(动态规划)
查看>>
Django 源码阅读:服务启动(wsgi)
查看>>
Django 源码阅读:url解析
查看>>
Docker面试题(一)
查看>>
第一轮面试题
查看>>
2020-11-18
查看>>
Docker面试题(二)
查看>>
一、redis面试题及答案
查看>>
消息队列2
查看>>
C++ 线程同步之临界区CRITICAL_SECTION
查看>>
测试—自定义消息处理
查看>>
MFC中关于虚函数的一些问题
查看>>
根据图层名获取图层和图层序号
查看>>
规范性附录 属性值代码
查看>>
提取面狭长角
查看>>
Arcsde表空间自动增长
查看>>
Arcsde报ora-29861: 域索引标记为loading/failed/unusable错误
查看>>
记一次断电恢复ORA-01033错误
查看>>