搭建一个springmvc helloworld程序
1、加jar包,需要8个,从springframework里面选
logging core aop context expression bean web webmvc

2、配置web.xml,在文件中配置一个servlet
<?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"> <servlet>
<servlet-name>dispatcherServlet</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>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
注意:1、contextConfigLocation 可以不配,默认找/WEB-INF/servlet-name + "-servlet.xml";2、servlet配置为加载项目时自动启动;3、默认url-pattern为/处理所有请求
3、写一个pojo 注解为controller
package com.hy.springmvc; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloWorld { @RequestMapping("/helloworld")
public String hello() {
System.out.println("hello");
return "success";
}
}
4、编写springmvc配置文件
<?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" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!-- 配置包扫描 -->
<context:component-scan base-package="com.hy.springmvc"></context:component-scan>
<!-- 配置视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
分别配置包扫描和视图解析器InternalResourceResolver(prefix + rerturn string + suffix)
5、建立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>welcome page</title>
</head>
<body>
<a href="helloworld">Hello World</a>
</body>
</html>
注意:href直接配置helloworld 不要/helloworld..
搭建一个springmvc helloworld程序的更多相关文章
- SpringMVC(一):搭建一个SpringMVC helloword项目
操作步骤: 1)下载spring framework开发包,给eclipse安装spring开发插件,如何安装开发插件&下载开发包请参考我的博文:<Spring(一):eclipse上安 ...
- 自己动手搭建 Redis 环境,并建立一个 .NET HelloWorld 程序测试
关于 Redis ,下面来自百度百科: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...
- 自己动手搭建 Redis 环境,并建立一个 .NET HelloWorld 程序测试(转)
关于 Redis ,下面来自百度百科: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...
- 自己动手搭建 MongoDB 环境,并建立一个 .NET HelloWorld 程序测试
关于 MongoDB,下面来自百度百科: MongoDB[1]是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. mongoDB[1] Mon ...
- 搭建一个springMVC项目以及遇到的问题
首先找到jar包(lz现在还在学习maven,以后回了,就用maven了,自己配置时,jar包不全就很容易到时搭建失败)
- Spring+SpringMVC+MyBatis深入学习及搭建(十三)——SpringMVC入门程序(二)
1.非注解的处理器映射器和适配器 1.1非注解的处理器映射器 前面我们配置的org.springframework.web.servlet.handler.BeanNameUrlHandlerMapp ...
- SpringMVC入门--编写一个SpringMVC小程序
一.SpringMVC的优势 Spring 为展现层提供的基于 MVC 设计理念的优秀的Web 框架,是目前最主流的 MVC 框架之一.Spring3.0 后全面超越 Struts2,成为最优秀的 M ...
- [转载]使用mpvue搭建一个初始小程序
1. 初始化一个 mpvue 项目 现代前端开发框架和环境都是需要 Node.js 的,如果没有的话,请先下载 nodejs 并安装. 然后打开命令行工具: # 1. 先检查下 Node.js 是否安 ...
- 使用mpvue搭建一个初始小程序
1. 初始化一个 mpvue 项目 现代前端开发框架和环境都是需要 Node.js 的,如果没有的话,请先下载 nodejs 并安装. 然后打开命令行工具: # 1. 先检查下 Node.js 是否安 ...
随机推荐
- 无法在web服务器上启动调试。Microsoft Visual Studio 远程调试监视器(MSVSMON.EXE)似乎没有在远程计算机上运行,VS2012调试错误
1.重启(无用) 2.关闭防火墙(无用) 3.开启文件与打印机共享(无用) 4.无远程调试权限,改为本地调试.或者是IIS中此项目没有启动.或者没有在IIS中新建此项目.
- 【转】第6篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+自动反射方法分析
作者: 牛A与牛C之间 时间: 2013-11-21 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第6篇:Xilium CefGlue 关于 CLR Object 与 JS ...
- Apache ab并发负载压力测试
由于现在网站都需要能够承受高并发要求的能力,所以当我们写完代码后,如果需要上线,最好都经过压力测试后,这样比较好 运行: 在Windows系统下,打开cmd命令行窗口,定位到apache安装目录的bi ...
- AJAX状态值与状态码
在<Pragmatic Ajax A Web 2.0 Primer > 0: (Uninitialized) the send( ) method has not yet been inv ...
- HDP2.4安装(一):Centos7安装
在进入大数据领域来,一直使用微软的Azure HDInsight,当前在中国区仅支持在Windows系统上部署集群,虽然创建的过程很简单,但对于开发人员来说,就是一个黑盒子,在更深入的研究和开发扩展的 ...
- 【linux】Cache和Buffer的区别
- Install Apache, PHP And MySQL On CentOS 7 (LAMP)
This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 suppor ...
- android学习笔记五——AutoCompleteTextView
AutocompleteTextview ==> 使用比较容易,只需要为其设置一个Adapter,该Adapter封装其需要预设的文本内容. 如下所示实例: <RelativeLayout ...
- 我的IT相关网址收藏
it语言学习免费视频: 尚学堂:http://www.sxt.cn/ 慕课网:http://www.imooc.com/course/list 大学生自学网:http://v.dxsbb.com/ 尚 ...
- Css3_写出小广播样子
/* create an arrow that points up */ div.arrow-up { width:0px; height:0px; border-left:5px solid tra ...