zoukankan      html  css  js  c++  java
  • 在MyEclipse中搭建Spring MVC开发环境

    环境版本 
    IDE:MyEclipse 8.5 
    Spring:spring 3.2.8 
    JDK:1.6

    1.打开MyEclipse-->File-->New-->Web Project,在打开的对话框里面输入project Name为SpringMvc,点击Finish。如下图所示:

    image

    2.在新建项目上右键选择,properties-->Java Build Path-->Libraries-->Add External JARs,引入spring-framework-3.2.8.RELEASE-dist目录下几个必需的jar包.

    下载地址:http://repo.spring.io/libs-release-local/org/springframework/spring/

    image

    3.文件结构

    image

    4.web.xml配置:

    <?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">       <servlet>              <servlet-name>springmvc</servlet-name>              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>       </servlet>             <servlet-mapping>              <servlet-name>springmvc</servlet-name>              <!-- 监听所有请求 -->              <url-pattern>/</url-pattern>       </servlet-mapping></web-app>

    5.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/mvc              http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd              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-3.0.xsd">       <!-- 扫描所有的 controller -->       <context:component-scan base-package="com.springmvc.controllers" />       <!-- 启动注解驱动 SpringMVC 功能 -->       <mvc:annotation-driven />       <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">              <property name="prefix" value="/views/" />              <property name="suffix" value=".jsp" />       </bean></beans>

    6.在WebRoot目录下,新建views文件夹,添加index.jsp.

    image

    7.在com.springmvc.controllers包下,新建HomeController类文件,

    image

    8.部署项目运行,访问http://localhost:8080/SpringMvc/home,如下图示:

    image

  • 相关阅读:
    会话管理?
    为什么要用 Dubbo?
    abstract class和interface有什么区别?
    接口是否可继承接口?抽象类是否可实现(implements)接口?抽象类是否可继承具体类(concrete class)?抽象类中是否可以有静态的main方法?
    用最有效率的方法算出2乘以8等於几?
    如何把一段逗号分割的字符串转换成一个数组?
    查看文件内容有哪些命令可以使用?
    使用哪一个命令可以查看自己文件系统的磁盘空间配额 呢?
    Spring框架中的单例bean是线程安全的吗?
    你更倾向用那种事务管理类型?
  • 原文地址:https://www.cnblogs.com/ruiati/p/5501585.html
Copyright © 2011-2022 走看看