Spring3.2 HelloWorld
来源:互联网 发布:平板怎么登录淘宝卖家 编辑:程序博客网 时间:2024/06/03 12:15
直接上图吧:
jar包:
项目目录一览:
这里的HelloWeb-servlet,xml 是在WEB-INF 下
HelloController:
package com.cqu.tutorial;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@RequestMapping("/hello")public class HelloController {@RequestMapping(method=RequestMethod.GET)public String printHello(ModelMap model){model.addAttribute("message","Hello Spring mvc");return "hello";}}
在WEB-INF 下建立web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>HelloWeb</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>HelloWeb</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
这里要注意<url-pattern> 要是"/“ ,之前我用”*.jsp“ 它会提示找不到mapping的路径
然后在同级目录下建立HelloWeb-servlet.xml 这里的HelloWorld 一定要和web里面的servlet-name对应
<?xml version="1.0" encoding="UTF-8"?><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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="com.cqu.tutorial"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/hello/" /> <property name="suffix" value=".jsp" /> </bean></beans>
<%@ 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>Hello Spring MVC</title></head><body><h2>${message}</h2></body></html>
然后运行,http://localhost:8080/HelloSpring 这样是不会有东西的,自己添加/hello 就可以了:http://localhost:8080/HelloSpring/hello
1 0
- Spring3.2 HelloWorld
- Spring3 MVC Tutorial helloworld
- CXF 2.3 集成Spring3.0入门 HelloWorld
- 初学spring3.05,一个helloworld例子
- spring3.2
- spring3(2)
- Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目
- 【Spring】Spring3.0.5的下载、配置与Helloworld
- Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目
- Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目
- Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目
- spring3.2新特性
- spring3.2学习第一节
- spring3+struts2+mybatis3 -2
- spring3.2配置文件
- 【Spring3】(2)常用注入
- spring3笔记2-IOC
- spring3
- Unique Binary Search Trees II
- execute、executeQuery、executeUpdate
- 转换字母
- 日经社説 20141215 「多弱」による勝利に慢心は許されぬ
- android vnc
- Spring3.2 HelloWorld
- 索引文件的并发访问和线程安全性
- XML解析
- Android编译系统详解(二)
- java实现页面加载更多功能
- VS2010 连接程序失败的解决办法
- 编辑手账 20141215 衆院選自公圧勝 重い信任を政策遂行に生かせ
- oracle中数据库,实例,表空间和用户之间的关系
- LEETCODE: Substring with Concatenation of All Words