gradle下的第一个SpringMVC应用
新建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应用的更多相关文章
- Spring MVC框架下的第一个Hello World程序
本程序是一个maven程序,使用maven方便管理jar包和程序,简化了操作步骤.本程序的目的是通过一个简单的程序,了解Spring MVC框架的基本工作流程,由简入繁的学习Spring MVC框架, ...
- SpringMVC(一):搭建一个SpringMVC helloword项目
操作步骤: 1)下载spring framework开发包,给eclipse安装spring开发插件,如何安装开发插件&下载开发包请参考我的博文:<Spring(一):eclipse上安 ...
- 看年薪50W的架构师如何手写一个SpringMVC框架
前言 做 Java Web 开发的你,一定听说过SpringMVC的大名,作为现在运用最广泛的Java框架,它到目前为止依然保持着强大的活力和广泛的用户群. 本文介绍如何用eclipse一步一步搭建S ...
- (一)SpringMvc简介以及第一个springmvc工程
一.SpringMVC是什么? springmvc是Spring的一个模块,提供web层解决方案(就与MVC设计架构) 如上图, DispatcherServlet:前端控制器,由SpringMVC提 ...
- SpringMVC_001 第一个SpringMVC程序
今天我们来学习第一个SpringMVC程序 一.配置开发方式 (1)首先建立一个SpringMVC web程序 (2)导入jar包 (3)建立UserController.java package ...
- 第一个SpringMVC程序 (配置版)
通过配置版本的MVC程序,可以了解到MVC的底层原理,实际开发我们用的是注解版的! 1.新建一个普通Maven的项目,然后添加web的支持 2.导入相关的SpringMVC的依赖 3.配置web.xm ...
- SpringMVC-02 第一个SpringMVC程序
SpringMVC-02 第一个SpringMVC程序 第一个SpringMVC程序 配置版 新建一个Moudle , springmvc-02-hello,确定依赖导入进去了 1.配置web.xml ...
- SpringMVC学习02(我的第一个SpringMVC程序)
2.Hello,SpringMVC 2.1 配置版 1.新建一个Moudle , springmvc-02-hello , 添加web的支持! 2.确定导入了SpringMVC 的依赖! 3.配置we ...
- Ubuntu系统下的第一个console程序
进入自己喜欢的目录,前面步骤和windows基本一致,只简单描述下 执行 dotnet new 然后执行 dotnet restore 然后执行 dotnet run 第一次未编译,会自动编译,然后可 ...
随机推荐
- jQuery客户端分页
01 <script src="/js/jquery-1.4.1.js" type="text/javascript"></script> ...
- java基础复习二——面向对象一
面向对象三大特性:封装,继承,多态 类:对象的蓝图,生成对象的模板,是对一类事物的描述,是抽象的概念上的定义 对象:是实际存在的该类事物的每个个体,也称为实例 类之间三种关系:依赖关系(uses-a) ...
- 关于Struts2的action的execute方法
这个方法必须要有一个String类型的返回值,所以如果写很多if else的话,记得要在最后加一个else,就是无论如何就会放回一个字符串,否则编译会报错,在execute方法名字下面有红线.
- Oracle数据库中,在SQL语句中连接字符串的方法是哪个?(选择1项)
Oracle数据库中,在SQL语句中连接字符串的方法是哪个?(选择1项) A.cat B.concat C.join D.+ 解答:B
- erlang的catch和 try catch的初步猜测
一. catch(Fun):似乎可以避免因为 函数Fun内的错误而造成的当前的进程的崩溃.
- php 输出带变量字符串(echo 函数的应用)
转自: http://www.cnblogs.com/devcjq/articles/2306150.html 学习PHP从最简单的开始:echo, print<?php$temp = arr ...
- par函数的bg参数-控制图片的背景色
bg 参数用于控制图片的背景色,默认为白色 代码示例: par(bg = "pink") plot(1:5, 1:5, main = "title", xlab ...
- CSS清除浮动常用方法小结
1.使用空标签清除浮动.我用了很久的一种方法,空标签可以是div标签,也可以是P标签.我习惯用<P>,够简短,也有很多人用<hr>,只是需要另外为其清除边框,但理论上可以是任何 ...
- MathType只有你会的几个技巧
太阳的后裔终于结局了,我们的乔妹被宋仲基撩走了,其中的撩妹技能你学到了几招?没学会,不要紧,还有MathType!只要你会MathType这几个技巧,撩妹绝对杠杠的.这可是连宋仲基都不会的! Math ...
- XML高速入门
XML是什么 Extensible Markup Language 自己定义标签: 用来数据传输: 可扩展标记语言,是一种类似超文本标记语言的标记语言. 与HTML的比較: 1.不是用来替代HTML的 ...