SpringMVC之HelloWorld
2019独角兽企业重金招聘Python工程师标准>>>
1.导入jar包,这里需要7个jar包
·spring-aop-x.x.x.RELEASE.jar
·spring-beans-x.x.x.RELEASE.jar
·spring-context-x.x.x.RELEASE.jar
·spring-core-x.x.x.RELEASE.jar
·spring-expression-x.x.x.RELEASE.jar
·spring-web-x.x.x.RELEASE.jar
·spring-webmvc-x.x.x.RELEASE.jar
2.配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID" version="3.1"><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 配置DispatcherServlet的一个初始化参数:配置SpringMVC 配置文件的位置和名称 --><!-- 实际上也可以不通过contextConfigLocation来配置SpringMVC的配置文件,而使用默认的 默认的配置文件为:/WEB-INF/<servlet-name>-servlet.xml springDispatcherServlet-servlet.xml --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>
3.在src下新建springmvc.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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"><!-- 配置自动扫描的包 -->
<context:component-scan base-package="com.f145a.springmvc"></context:component-scan><!-- 配置视图解析器 :如何把handler方法返回值解析为实际的物理视图-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!--前缀--><property name="prefix" value="/WEB-INF/views/"></property><!--后缀--><property name="suffix" value=".jsp"></property>
</bean>
</beans>
4.新建index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="helloworld">Hello World</a>
</body>
</html>
5.在com.f145a.springmvc.handlers下新建HelloWorld.Java
package com.f145a.springmvc.handlers;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class HelloWorld {/*** 1.使用@RequestMapping注解来映射请求的URL* 2.返回值会通过视图解析器解析为实际的物理视图,对于InternalResourceViewResolver视图解析器,会做如下的解析:* 通过prefix+returnVal+后缀 这样的方式得到实际的物理视图,然后做转发操作* /WEB-INF/views/success.jsp* @return*/@RequestMapping("/helloworld")public String hello(){System.out.println("hello World!");return "success";}
}
6.在WEB-INF下新建views文件夹,并添加success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h4>成功页面!</h4>
</body>
</html>
7.运行程序,在地址栏输入http://localhost:8080/springmvc-1/
欢迎访问我的个人博客http://www.chengzequn.top
转载于:https://my.oschina.net/chengzequn/blog/779577
SpringMVC之HelloWorld相关推荐
- 关于springmvc的helloworld的压测报告
都说hello world 很简单,应该能承受很大的请求压力,那么到底有多大?你知道吗?如果知道,那咱们就不继续了.如果不知道,我们来看一下! 1. 准备工作,快速建立一个基于springmvc的he ...
- Springmvc的helloworld实例
1. 新建package Src->new->other->package 输入包名:org.tgb.web.controller 点击"finish" 2 ...
- 学习SpringMVC——从HelloWorld开始
前言: 时隔十二年,中国女排最终过关斩将,用3:1的成绩证明了自己的实力,霸气夺冠,为中国赢得了一枚意义非常的金牌.这是一次全民的狂欢,一场视听盛宴,带给我们不仅是熠熠生辉的金牌,更传递出的是一种女排 ...
- SpringMVC注解HelloWorld
今天整理一下SpringMVC注解 欢迎拍砖 @RequestMapping RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是 ...
- SpringMVC之“HelloWorld”起步
添加jar包 在eclipse中创建一个web应用程序后,向"WEB-INF\lib"中添加以下SpringMVC必须的jar包: - commons-logging-1.2.ja ...
- SpringMVC 2.HelloWorld
面向对象面向君,不负代码不负卿. *^o^* SpringMVC HelloWorld 1.建立SpringMVC的Maven工程 1.1 使用iIntelliJ IDEA 创建Maven工程 1. ...
- HelloWorld实例(springmvc版)
本文将对应用springmvc实现HelloWorld打印,其步骤如下: 1.加入相关jar包,在maven项目里就是在pom.xml文件中引入相关实际依赖 2.在web.xml文件中配置Dispat ...
- SpringMVC基础配置及使用
SpringMVC基础配置及使用 SpringMVC: 1.SpringMVC和Spring的关系: 软件开发的三层架构: web层[表示层.表现层]---->Service层----& ...
- 170821-关于SpringMVC的知识点
1.SpringMVC 概述以及优势 SpringMVC和Spring的关系: 软件开发的三层架构: web层[表示层.表现层]---->Service层---->Dao[DataBas ...
最新文章
- Lint found fatal errors while assembling a release target.
- java的工作原理你知道吗_每天用Mybatis,但是Mybatis的工作原理你真的知道吗?
- 一文带你看懂分布式软总线在家庭场景的应用
- Java ObjectStreamField getOffset()方法与示例
- HTML 字符实体 参考手册
- CVPR 2021 | 商汤提出最强时序动作提名修正网络:TCANet
- 不同分辨率图片匹配_超实用的图像超分辨率重建方法及应用介绍
- java+cache使用方法_JVM代码缓存区CodeCache原理及用法解析
- 朴素贝叶斯分类算法(Naive Bayesian classification)
- 生活娱乐 长的最奇怪的东西——骡耳犰狳
- A星(A*、A Star)路径规划算法详解(附MATLAB代码)
- 怎样才算是优质的Scratch作品?
- Canceled future for execute_request message before replies were done The Kernel crashed while execut
- 利用梳状函数求解周期函数傅里叶变换
- 来自清华学子的一个自述---在树洞里
- python在医学中的应用_如何应用Python处理医学影像学中的DICOM信息
- Html及常用标签简介
- MATLAB与数学建模:初阶绘图
- 云服务器系统种类,云服务器系统种类
- PHP邮件发送:PHP使用SMTP服务器发送邮件
热门文章
- Python脚本实现启停app获取资源占比信息
- SVO实时全局光照优化(里程碑MK2):Sparse Voxel Octree based Global Illumination (SVO GI)...
- Linux课程实践一:Linux基础实践(SSH)
- UIKit应用 - Swift 版本: 3.让UITableViewCell的背景色渐变
- 添加MD5 密码加密
- VC++2012编程演练数据结构《12》二叉排序树
- 组件:slot插槽、组件:组合slot
- MyBatis 简介、 环境搭建、数据库连接池、查询方式
- PostgreSQL客户端psql常用命令
- zookeeper下载地址及常见配置项