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程序的更多相关文章

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

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

  2. 自己动手搭建 Redis 环境,并建立一个 .NET HelloWorld 程序测试

    关于 Redis ,下面来自百度百科: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

  3. 自己动手搭建 Redis 环境,并建立一个 .NET HelloWorld 程序测试(转)

    关于 Redis ,下面来自百度百科: redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

  4. 自己动手搭建 MongoDB 环境,并建立一个 .NET HelloWorld 程序测试

    关于 MongoDB,下面来自百度百科: MongoDB[1]是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案.   mongoDB[1] Mon ...

  5. 搭建一个springMVC项目以及遇到的问题

    首先找到jar包(lz现在还在学习maven,以后回了,就用maven了,自己配置时,jar包不全就很容易到时搭建失败)

  6. Spring+SpringMVC+MyBatis深入学习及搭建(十三)——SpringMVC入门程序(二)

    1.非注解的处理器映射器和适配器 1.1非注解的处理器映射器 前面我们配置的org.springframework.web.servlet.handler.BeanNameUrlHandlerMapp ...

  7. SpringMVC入门--编写一个SpringMVC小程序

    一.SpringMVC的优势 Spring 为展现层提供的基于 MVC 设计理念的优秀的Web 框架,是目前最主流的 MVC 框架之一.Spring3.0 后全面超越 Struts2,成为最优秀的 M ...

  8. [转载]使用mpvue搭建一个初始小程序

    1. 初始化一个 mpvue 项目 现代前端开发框架和环境都是需要 Node.js 的,如果没有的话,请先下载 nodejs 并安装. 然后打开命令行工具: # 1. 先检查下 Node.js 是否安 ...

  9. 使用mpvue搭建一个初始小程序

    1. 初始化一个 mpvue 项目 现代前端开发框架和环境都是需要 Node.js 的,如果没有的话,请先下载 nodejs 并安装. 然后打开命令行工具: # 1. 先检查下 Node.js 是否安 ...

随机推荐

  1. 021. asp.net两个DataSet数据集的合并

    protected void Page_Load(object sender, EventArgs e) { DataSet dsSource = new DataSet(); //创建源数据集 Da ...

  2. unity, 取消ugui button响应键盘

    http://answers.unity3d.com/questions/859460/button-is-being-triggered-by-spacebar-after-clicke.html

  3. c#, 输出二进制

    int x=-17; string str= Convert.ToString(x,2);Debug.Log(str); 输出结果: 11111111111111111111111111101111 ...

  4. 数据接口管理工具 thx RAP

    RAP是数据接口管理工具.在开发时前端将请求转至RAP,由RAP提供模拟数据:而后端使用RAP测试接口的正确性.这样RAP就成为了开发过程中的强 依赖,进而确保接口文档的实时正确性.RAP采用JSON ...

  5. [oracle] ORA-08002:序列XXXXXXX.CURRVAL尚未在此进程中定义

    出现 ORA-08002: 序列XXXXXXX.CURRVAL 尚未在此进程中定义. 导致原因:因为是首次查询序列的当前值,内存中之前并没有缓存序列的任何值,所以需要先查询 一下序列的下一个值(此时, ...

  6. 用Bouncy Castle的C#版API产生公钥和私钥

    开源API链接地址:The Legion of the Bouncy Castle Bouncy Castle,简称为BC,原本是java的一个开源JCE提供者,后来也提供了C#版本的API,我下载其 ...

  7. 【shell】通配符

    ‘’与“” [root@andon ~]# name='$date' [root@andon ~]# echo $name $date [root@andon ~]# name=abc [root@a ...

  8. UI设计的重要性--避免二义性的输入提示

    昨天晚上发现了西安公路客运网上售票系统网站的密码找回系统存在安全漏洞,得出的结论是:密码找回页的漏洞:   1.用户名栏支持用户名.身份证.电话三种任意一种匹配.2.这一步是关键,密码找回问题提示栏居 ...

  9. get utc+8 当时时间

    /// <summary> /// get utc+8 当时时间 /// </summary> /// <returns></returns> publ ...

  10. 剑指offer系列25---构建乘积数组

    [题目]给定一个数组A[0,1,…,n-1],请构建一个数组B[0,1,…,n-1],其中B中的元素B[i]=A[0]A[1]…A[i-1]A[i+1]…A[n-1].不能使用除法. package ...