Java WEB SpringMvc框架简单入门
来源:互联网 发布:淘宝宝贝拍照灯光选择 编辑:程序博客网 时间:2024/04/29 14:47
1.Jar包准备(最小jar包集合)
导入上述jar包
2.修改web.xml配置文件(WEB-INF下的web工程配置文件)
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.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:springmvc-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>3.配置spring框架配置文件(放在src下)
<?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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- scan the package and the sub package --> <context:component-scan base-package="top.mzp.test"/> <!-- don't handle the static resource --> <mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting --> <mvc:annotation-driven /> <!-- configure the InternalResourceViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> <!-- 前缀 --> <property name="prefix" value="/WEB-INF/" /> <!-- 后缀 --> <property name="suffix" value=".jsp" /> </bean> </beans>
上述配置文件: base-package="top.mzp.test" 配置处理类(后面有描述)
property name="prefix" value="/WEB-INF/" 代表的是视图文件的路径3.新建处理类package top.mzp.test; import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/mvc")public class mvcController {@RequestMapping("/hello")public String hello() {return "index";}}其中:("/mvc")是访问的路径,"/hello"是访问的URLreturn "index"; index是访问的视图文件的名字(index.jsp)4.不熟项目之后,访问:http://localhost:8080/springMvc02/mvc/hello
阅读全文
0 0
- Java WEB SpringMvc框架简单入门
- java web ssh三大框架整合简单入门
- Java-springMVC框架:springMVC简单搭建一
- 一个简单的SpringMVC框架web程序
- SpringMvc一个简单的框架入门程序
- Java Web开发SpringMVC和MyBatis框架开发环境搭建和简单实用
- JAVA WEB搭建 SpringMVC+Spring+hibernate 框架
- JAVA WEB搭建 SpringMVC+Spring+hibernate 框架
- Java Web开发简单入门
- 快速搭建简单的springMvc框架的动态web工程
- Springmvc整合tiles框架简单入门示例(maven)
- 【SSM-SpringMVC框架】SpringMVC入门
- SpringMVC-轻量级Web框架
- springMVC框架入门
- SpringMVC框架入门
- SpringMVC框架入门使用
- springmvc入门---框架搭建
- springmvc框架快速入门
- POJ:2109-Power of Cryptography(关于double的误差)
- ZOJ
- 初学Python第八天
- ACdream 1069无耻的出题人
- 可持久化数据结构
- Java WEB SpringMvc框架简单入门
- Linux内存管理机制
- 【死磕Netty】-----NIO基础详解
- ServletContext简介(七)
- 习题7.3
- 登录的时候,命令提示符变成了-bash-4.1$ 如何解决?
- 自定义组合控件,实现无限轮播
- 无旋treap的初步学习
- 51nod 1277 字符串中的最大值 (kmp之next数组的理解) O(n)可过