新建gradle project

缺少了很多文件夹和文件,我们自己补充,补充完的目录如下:

HelloController:

package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/test")
public class HelloController { @RequestMapping("/hello")
public ModelAndView del(HttpServletRequest request,
HttpServletResponse response) {
System.out.println("----del----");
return new ModelAndView("/hello", "message", "你好");
}
}

spring-mvc.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> <!-- scan the package and the sub package -->
<context:component-scan base-package="controller"/> <!-- don't handle the static resource -->
<mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven /> <!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"> <!--START 设置字符编码过滤器-->
<filter>
<description>字符集过滤器</description>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>字符集编码</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--END 设置字符编码过滤器--> <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-mvc.xml</param-value>
</init-param>
<!-- <load-on-startup>1</load-on-startup> -->
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>

index.jsp:

<%--
Created by IntelliJ IDEA.
User: sawyer
Date: 2018/4/19
Time: 下午11:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>我的主页</title>
</head>
<body>
你好,世界
</body>
</html>

hello.jsp:

<%--
Created by IntelliJ IDEA.
User: sawyer
Date: 2018/4/20
Time: 上午12:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${message}helloWorld </body> </html>

  

验证效果:

  

gradle下的第一个SpringMVC应用的更多相关文章

  1. Spring MVC框架下的第一个Hello World程序

    本程序是一个maven程序,使用maven方便管理jar包和程序,简化了操作步骤.本程序的目的是通过一个简单的程序,了解Spring MVC框架的基本工作流程,由简入繁的学习Spring MVC框架, ...

  2. SpringMVC(一):搭建一个SpringMVC helloword项目

    操作步骤: 1)下载spring framework开发包,给eclipse安装spring开发插件,如何安装开发插件&下载开发包请参考我的博文:<Spring(一):eclipse上安 ...

  3. 看年薪50W的架构师如何手写一个SpringMVC框架

    前言 做 Java Web 开发的你,一定听说过SpringMVC的大名,作为现在运用最广泛的Java框架,它到目前为止依然保持着强大的活力和广泛的用户群. 本文介绍如何用eclipse一步一步搭建S ...

  4. (一)SpringMvc简介以及第一个springmvc工程

    一.SpringMVC是什么? springmvc是Spring的一个模块,提供web层解决方案(就与MVC设计架构) 如上图, DispatcherServlet:前端控制器,由SpringMVC提 ...

  5. SpringMVC_001 第一个SpringMVC程序

    今天我们来学习第一个SpringMVC程序 一.配置开发方式 (1)首先建立一个SpringMVC  web程序 (2)导入jar包 (3)建立UserController.java package ...

  6. 第一个SpringMVC程序 (配置版)

    通过配置版本的MVC程序,可以了解到MVC的底层原理,实际开发我们用的是注解版的! 1.新建一个普通Maven的项目,然后添加web的支持 2.导入相关的SpringMVC的依赖 3.配置web.xm ...

  7. SpringMVC-02 第一个SpringMVC程序

    SpringMVC-02 第一个SpringMVC程序 第一个SpringMVC程序 配置版 新建一个Moudle , springmvc-02-hello,确定依赖导入进去了 1.配置web.xml ...

  8. SpringMVC学习02(我的第一个SpringMVC程序)

    2.Hello,SpringMVC 2.1 配置版 1.新建一个Moudle , springmvc-02-hello , 添加web的支持! 2.确定导入了SpringMVC 的依赖! 3.配置we ...

  9. Ubuntu系统下的第一个console程序

    进入自己喜欢的目录,前面步骤和windows基本一致,只简单描述下 执行 dotnet new 然后执行 dotnet restore 然后执行 dotnet run 第一次未编译,会自动编译,然后可 ...

随机推荐

  1. 解决spring-boot-starter-logging与log4j冲突

    由于公司在super-bom里配置了检查规则,build项目时遇到错误: [ERROR] [XXX Enforcer Rules] find DuplicateClasses Found in:org ...

  2. pick王菊?作为“菊外人”的程序员能做点什么?

    转载:https://mp.weixin.qq.com/s/s1cb9Ij6ouTYYCZovLhXTA 最近,想必大家的朋友圈都被“王菊”占领了,打开朋友圈到处可以见到“pick王菊”.“陶渊明”. ...

  3. easyUI datagrid 排序

    easyUI datagrid 排序 1.首先设置datagrid属性sortName 2.设置sortOrder 3.设置remoteSort(注:此属性默认为true,如果如果是对本地数据排序必须 ...

  4. jquery对象和javascript的dom对象转换

    Jquery框架为jquery对象定义了独立使用的方法和属性,它无法直接调用dom对象的方法,dom对象也无法直接调用jquery对象的方法和属性. Jquery对象和dom对象是可以相互转换的,因为 ...

  5. AOP——引言

    转自:http://wayfarer.cnblogs.com/articles/241012.html 1.引言 2.AOP技术基础3.Java平台AOP技术研究 4..Net平台AOP技术研究 软件 ...

  6. php插入htm htm插入php的变量

    <?php $file = "ueditor\php\upload\image\*\*.png"; foreach (glob("$file") as $ ...

  7. 关于Cocos2d-x中数据的存储

    当局分数的打印和最高分数的记录 1.首先定义一个Label类型的节点在GameScene.cpp的init方法中,设置初始分数为0 _myScore = 0; scorelabel = Label:: ...

  8. Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering

    Defferrard, Michaël, Xavier Bresson, and Pierre Vandergheynst. "Convolutional neural networks o ...

  9. 第三百零八节,Django框架,models.py模块,数据库操作——链表结构,一对多、一对一、多对多

    第三百零八节,Django框架,models.py模块,数据库操作——链表结构,一对多.一对一.多对多 链表操作 链表,就是一张表的外键字段,连接另外一张表的主键字段 一对多 models.Forei ...

  10. 转载:15个最受欢迎的Python开源框架

    出自:http://python.jobbole.com/72306/?replytocom=57112 15个最受欢迎的Python开源框架 Django: Python Web应用开发框架 Dja ...