springMVC入门程序helloworld
来源:互联网 发布:上海雕塑培训班 知乎 编辑:程序博客网 时间:2024/05/17 03:46
1.建新工程
2.配置web.xml文件及在WEN-INF下lib中加入Jar包
JAR包为整个springmvc常用的所以多一些!
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" 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"> <display-name>springMVC</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:springmvc-servlet.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>
3.在src下添加springmvc-servlet.xml配置文件
<?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/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.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- scan the package and the sub package --> <context:component-scan base-package="test.SpringMVC"/> <!-- 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/jsp/" /> <!-- 后缀 --> <property name="suffix" value=".jsp" /> </bean></beans>
4..在WEB-INF文件夹下创建名为jsp的文件夹,用来存放jsp视图。创建一个hello.jsp,在body中添加“Hello World”。
hello.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=ISO-8859-1"><title>Insert title here</title></head><body>Hello World!</body></html>
5.在src下建test.SpringMVC包并在包下建个mvcController.java
mvcController.java代码
package test.SpringMVC;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/mvc")public class mvcController { @RequestMapping("/hello") public String hello(){ return "hello"; }}
阅读全文
1 0
- springMVC 入门程序 helloworld!
- springMVC入门程序helloworld
- SpringMVC基础入门,创建一个HelloWorld程序
- SpringMVC基础入门--创建一个HelloWorld程序
- SpringMVC基础入门,创建一个HelloWorld程序
- SpringMVC基础入门,创建一个HelloWorld程序
- SpringMVC入门一:helloWorld
- 001-SpringMVC入门--HelloWorld
- SpringMVC入门HelloWorld
- 一、SpringMVC基础入门,创建一个HelloWorld程序
- 一、SpringMVC基础入门,创建一个HelloWorld程序
- 一、SpringMVC基础入门,创建一个HelloWorld程序
- springMVC + maven helloworld程序
- SpringMVC创建HelloWorld程序
- SpringMVC学习笔记---- 一、SpringMVC基础入门,创建一个HelloWorld程序
- springMvc入门--又是HelloWorld
- 一、SpringMVC入门,实现HelloWorld
- mybatis入门HelloWorld程序
- 1021. Deepest Root (25)(图的直径)
- 遗传算法的TSP例子
- 数据分析处理库Pandas-数据读取
- 基于SoC成像芯片MT9M111和CY7C68013的视频采集
- 《操作系统之哲学原理》笔记一
- springMVC入门程序helloworld
- 矩阵快速幂板子
- 欢迎使用CSDN-markdown编辑器
- Codeforces Round #444 (Div. 2) D. Ratings and Reality Shows 贪心
- 老毛桃制作U盘-linux
- 编程语言 | Java
- 类型判断type与isinstance的区别
- Django快速搭建博客 第二节 项目迁移到pycharm
- Math类和BigDecimal 类型