IDEA创建Springmvc项目
项目主要步骤如下:
1.创建一个javaweb动态项目
2.导入springmvc demo所需要的jar包
3.生成项目war包
4.配置项目tomacat服务器
5.配置web.xml文件
6.编写测试jsp界面、编写程序入口jsp页面
7.生成dispatcherServlet-servlet.xml文件并配置
8.编写测试类测试
9.测试成功
1.创建一个javaweb动态项目
2.导入springmvc demo所需要的jar包
3.生成项目war包
4.配置项目tomacat服务器
5.配置web.xml文件
<!-- 配置 DispatcherServlet -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置 DispatcherServlet 的一个初始化参数: 配置 SpringMVC 配置文件的位置和名称 -->
<!--
实际上也可以不通过 contextConfigLocation 来配置 SpringMVC 的配置文件, 而使用默认的.
默认的配置文件为: /WEB-INF/<servlet-name>-servlet.xml
-->
<!--<init-param>-->
<!--<param-name>contextConfigLocation</param-name>-->
<!--<param-value>classpath:springmvc.xml</param-value> src目录下的springmvc.xml-->
<!--</init-param>-->
<!---->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<!--哪些请求可以交给servlet处理
<url-pattern>/</url-pattern> 中的/表示所有文件交给servlet处理
-->
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
6.编写测试jsp界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>success page</h1>
</body>
</html>
编写程序入口jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<a href="helloworld">HelloWorld</a>
</body>
</html>
7.生成dispatcherServlet-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"
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.xsd">
<!-- 配置自定扫描的包 -->
<context:component-scan base-package="com.springmvc000"></context:component-scan>
<!--配置视图解析器 如何把 handler 方法返回值解析为实际的物理视图-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
8.编写测试类测试
package com.springmvc000.handlers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloWorld {
/**
* 1.使用@RequestMapping注解来映射请求URL
* 2.返回值会通过视图解析器解析为实际的物理视图,对于InternalResourceViewResolver视图解析器,会做如下解析:
* 通过prefix + returnVal + 后缀 这样的方式得到实际的物理视图
* 然后会做转发操作
* 此处转发到/WEB-INF/views/success.jsp
* @return
*/
@RequestMapping("/helloworld")
public String hello(){
System.out.println("hello world");
return "success";
}
}
9.测试成功
IDEA创建Springmvc项目的更多相关文章
- springmvc学习笔记---idea创建springmvc项目
前言: 真的是很久没搞java的web服务开发了, 最近一次搞还是读研的时候, 想来感慨万千. 英雄没落, Eclipse的盟主地位隐隐然有被IntelliJ IDEA超越的趋势. Spring从2. ...
- 【SpringMVC】使用Myeclipse创建SpringMVC项目【超详细教程】
之前一直是使用Eclipse创建Web项目,用IDEA和MyEclipse的创建SpringMVC项目的时候时不时会遇到一些问题,这里把这个过程记录一下,希望能帮助到那些有需要的朋友.我是用的是MyE ...
- 工具idea 基于maven 创建springMVC项目
SpringMVC Spring MVC是Spring提供的一个强大而灵活的web框架.借助于注解,Spring MVC提供了几乎是POJO的开发模式,使得控制器的开发和测试更加简单.这些控制器一般不 ...
- 在eclipse中使用maven创建springMVC项目
一.在eclipse中创建maven-archetype-webapp项目: 1.新建项目选择maven项目 2.默认,下一步 3.选择maven-archetype-webapp,其他保持默认即可 ...
- eclipse创建springmvc项目
一.在eclipse中创建maven-archetype-webapp项目: 1.新建项目选择maven项目 2.默认,下一步 3.选择maven-archetype-webapp,其他保持默认即可 ...
- SpringMVC教程--eclipse中使用maven创建springMVC项目
一.在eclipse中创建maven-archetype-webapp项目: 1.新建项目选择maven项目 2.默认,下一步 3.选择maven-archetype-webapp,其他保持默认即可 ...
- SpringMVC教程--Idea中使用Maven创建SpringMVC项目
1.新建项目 参照idea教程中的创建maven项目https://www.cnblogs.com/daxiang2008/p/9061653.html 2.POM中加入依赖包 (1)指定版本 (2) ...
- SpringMVC+Hibernate 项目开发之三 (创建SpringMVC项目)
引用(很全面了):http://blog.csdn.net/dhx20022889/article/details/38041039 我只想说默认创建的项目使用的Spring版本可能不是你想要的,可以 ...
- IDEA用maven创建springMVC项目和配置
工具准备:IDEA2016.3 Java jdk 1.8 1.DEA创建项目 新建一个maven project,并且选择webapp原型. 然后点击next 这里的GroupId和Artifac ...
- sts 创建springMVC项目---- maven和tomcat 错误处理
今天学习spring的时候,学到了springMVC, 因为springMVC 就是beginning spring 书籍的第三章,为了更深入或更简单的起步学习springMVC, 我又找了另外一本书 ...
随机推荐
- root/base/stem概念
The verb root (or base form): 1.is the same as the infinitive不定式 (e.g., to dive, to jump, to wonder) ...
- lesson7cnn architecture-fastai
课程https://v.qq.com/x/page/e0398lijt8h.html 讲解: http://www.sohu.com/a/144583206_697750 resnet可以看作VGG1 ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- 第一天 hello world
二进制编译工具生成img软盘执行文件 二进制编译工具https://pan.baidu.com/s/1j3wAsFxTLWv17V55iNKJJw 利用Bz.exe工具写操作系统自启程序: 前0000 ...
- 计算x
如果x的x次幂结果为10(参见[图1.png]),你能计算出x的近似值吗? 显然,这个值是介于2和3之间的一个数字. 请把x的值计算到小数后6位(四舍五入),并填写这个小数值. 注意:只填写一个小数, ...
- C++数组排序
#include<stdio.h> #include<stdlib.h> #include<windows.h> #define SIZE 5 //数组中元素的数量 ...
- itcast-Hibernate orm元数据和 关系操作
在Hibernate安装包 project /etc/hibernate.property文件下 显示 ,格式化 映射导入映射文件 详解orm元数据 配置文件详解 generator主键生 ...
- mac-ppt-auto-open-recovery-files
mac 每次打开PPT都会出现一个自动保存的文件,不知道这个文件是保存在哪里,该怎么删除 打开finder(访达),按 shift+command+G,输入~/Library/Containers/c ...
- Cassandra基础
Apache Cassandra特性 Apache Cassandra由Facebook基于Amazon的Dynamo及其在Google的Bigtable上的数据模型设计开发的面相列的数据库,实现没有 ...
- MySQL导出用户权限
在MySQL 5.5/5.6版本中,使用SHOW GRANTS命令可以导出用户的创建脚本和授权脚本. hostname='127.0.0.1' port= username='root' passwo ...