springmvc 注解版helloworld
来源:互联网 发布:网络教育专本科 编辑:程序博客网 时间:2024/06/05 20:41
这是目录结构图。springmvc的helloworld的几个步骤:
一、添加jar包
二、配置web.xml(这一步struts2类似)
三、配置spring.xml
四、写action
五、写jsp访问
一、把从spring官网上下载的jar包都加进去,然后再加一个commons-logging-1.1.jar(spring依赖它做日志记录)。
二、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_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>HelloSpringMVC_SimpleAnnotation</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/spring.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
三、spring.xml的写法
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 注解扫描包 --> <context:component-scan base-package="com.evan" /> <!-- 开启注解 --> <mvc:annotation-driven /> <!-- 视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean></beans>
四、action的写法(HelloWorld.java)
package com.evan.action;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class HelloWorld { @RequestMapping("/hello") public String hello() { return "success"; }}
五 、succes.jsp的写法。(就在jsp页面加了一句“注解版springmvchelloworld”)
<%@ 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>注解版springmvchelloworld</body></html>
六、将项目加到tomcat,启动tomcat。然后访问地址:http://localhost:8080/HelloSpringMVC_SimpleAnnotation/hello
这样一个springmvc版的helloworld一句完成。如果以上讲的不清楚,那你可以到我的资源下载源码。免积分的。
资源的下载地址:http://download.csdn.net/detail/zl544434558/6364877
- springmvc 注解版helloworld
- SpringMVC annotation注解版helloworld
- spring和springMVC整合注解版helloworld
- SpringMVC学习笔记(2) 框架配置+HelloWorld(注解版)
- SpringMVC学习笔记(3) 框架配置+HelloWorld(非注解版)
- HelloWorld版的SpringMVC使用注解驱动的依赖注入
- HelloWorld版的SpringMVC使用注解驱动的依赖注入
- 基于注解实现springmvc的入门helloworld
- SpringMVC Helloworld注解和404问题
- springMVC-HelloWorld
- SpringMVC HelloWorld
- SpringMVC HelloWorld
- SpringMVC - HelloWorld
- springmvc helloworld
- springMVC helloworld
- 【SpringMVC】Helloworld
- SpringMVC学习笔记(三)使用IntelliJ IDEA开发Spring MVC HelloWorld(注解配置SpringMVC)
- springMVC----springMVC的HelloWorld
- IOS飞机大战OC版
- WPF 多国语言 localization
- 对“啊哈C v2.0”集成开发环境的一些感受 (LTS)
- proc/c++(二)
- 个人计划!
- springmvc 注解版helloworld
- tmpfs和sysfs
- Oracle DB 使用闪回技术2
- 牛逼的Android UI--第18章 与用户交互相关的设计模式 (下1)
- android开发案例之使用JSON数据向服务器提交和获取服务器传递的Json数据
- Android MediaRecorder获取音频流的方法
- 程序的链接与装入(动、静态重定位)
- javascript json
- sqlserver 数据行统计,秒查语句