SSM搭建-Spring MVC搭建第一个HelloWorld(12)
来源:互联网 发布:网络招聘怎么做 编辑:程序博客网 时间:2024/05/08 16:43
本文为博主林炳文Evankaka原创文章 出处http://blog.csdn.net/evankaka
第一个SpringMVC程序
工程免费下载
1、在eclipse中新建立一个web工程,首先将需要的包导入到\WebContent\WEB-INF\lib
2、先配置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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- id="WebApp_ID" version="3.0">
- <!-- SpringMVC的前端控制器 -->
- <servlet>
- <servlet-name>Hello</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <!-- 设置自己定义的控制器xml文件 -->
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/Hello-servlet.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <!-- Spring MVC配置文件结束 -->
- <!-- 拦截设置 -->
- <servlet-mapping>
- <servlet-name>Hello</servlet-name>
- <!-- 由SpringMVC拦截所有请求 -->
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- </web-app>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <!-- 把标记了@Controller注解的类转换为bean -->
- <context:component-scan base-package="com.mucfc" />
- <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
- <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
- p:prefix="/WEB-INF/views/" p:suffix=".jsp"/>
- </beans>
- package com.mucfc;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- @Controller
- public class HelloWorldController {
- @RequestMapping(value="/hello",method=RequestMethod.GET,params="userid")
- public String printWelcome(ModelMap model,String userid) {
- model.addAttribute("message", "Spring 3 MVC Hello World");
- return "hello";
- }
- }
[html] view plain copy print?
- <%@ page language="java" contentType="text/html; charset=gb2312"
- pageEncoding="gb2312"%>
- <!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=gb2312">
- <title>Insert title here</title>
- </head>
- <body>
- Message:${message}
- </body>
- </html>
7、直接运行,浏览器中输入http://localhost:8080/SpringMVCLearningChapter1/hello
结果如下:
0 0
- SSM搭建-Spring MVC搭建第一个HelloWorld(12)
- SSM搭建-Spring第一个Spring HelloWorld(2)
- 15、SSM框架-Spring MVC搭建第一个HelloWorld(2)
- SSM框架项目搭建系列(二)—Spring第一个HelloWorld
- 3、SSM框架-Spring第一个Spring HelloWorld(3)
- SSM搭建-Spring MVC介绍(11)
- SSM框架的搭建(Spring+SpringMVC+Mybatis第一个项目的搭建)
- 搭建第一个HelloWorld项目
- Spring-001-环境搭建与第一个HelloWorld
- SSM(spring+spring mvc+mybatis)框架搭建
- Eclipse 搭建SSM(Spring、Spring MVC 、Mybatis)
- SSM框架搭建(Maven+Spring+Spring MVC+MyBatis)
- 创建第一个Spring MVC程序helloworld
- SSM搭建-Spring mvc基于注解的配置(13)
- Spring Boot / Spring MVC 入门实践 (一) :环境搭建与第一个项目
- Spring Boot / Spring MVC 入门实践 (一) :环境搭建与第一个项目
- Spring Boot / Spring MVC 入门实践 (一) :环境搭建与第一个项目
- spring第一个项目搭建
- jquery checkbox实现单选小例
- Struts2小结-ValueStack-OGNL-EL
- C语言的一些优缺点
- node js- 路由转发和失败重试策略
- C语言入门级教程三
- SSM搭建-Spring MVC搭建第一个HelloWorld(12)
- spoj104 highways(矩阵树定理)
- ECSHOP后台编辑器上传中文名称图片乱码解决方法
- JAVA 中 Redis与ehcache对比与使用
- python3中报错:TypeError: 'range' object doesn't support item deletion
- Java回顾之多线程同步
- jQuery Ajax 实例详解 ($.ajax、$.post、$.get)
- html5笔记之新增选择器
- APUE笔记---第六章系统数据文件和信息操作