Java初体验之springMvc(一) springmvc框架的的引入

第一章,项目搭建以及springMvc的配置

Java这门语言我心驰神往已久,就让我们来一起做一个web项目,预计用到的东西有如下.

  • js
  • springMvc
  • json
  • sql
  • 定时任务

第一步 创建项目

我这里用的是eclipse,当然你们如果用其他的IDE也没有什么问题大同小异。其他的IDE我推荐是IDEA,这款用java的swing技术开发的一款IDE在操作的流畅程度来说还是不错的,但是对配置要求比较高
这里写图片描述

第二步 编写web.xml

这一步比较重要,可以说是特别重要。web.xml的位置在WebContent下面的web-inf下面。

<?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_2_5.xsd" id="WebApp_ID" version="2.5">

    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>
        login.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>

第三步 编写springmvc-servlet.xml

重要的是springmvc-servlet.xml和web.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
    <!-- mvc的注解驱动 -->   
    <context:annotation-config/>
    <!-- 扫描器 -->
    <context:component-scan base-package="com.*"></context:component-scan>
    <!-- 前缀+viewName+后缀 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!--webroot到某一指定文件夹的路径-->
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <!--视图名称的后缀-->
    <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

第四步 添加到tomcat中

这里写图片描述

然后启动tomcat,启动没有报错,那么我们的项目基本的结构就已经准备好了

下面是springMvc使用到的jar包 http://pan.baidu.com/s/1cJb5lc 密码v4jb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值