一、创建Web项目

  我用的eclipse,创建步骤:file=>New=>Other=>Web=>Dynamic Web project,按照操作创建一个完整的Web项目,下载对应的jar文件,复制到 lib文件夹下。

  Spring4 MVC HelloWord实例Spring4 MVC HelloWord实例

二、创建配置文件进行配置

1、新建文件 :

Spring4 MVC HelloWord实例

2、打开 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>我的MVC项目</display-name>
  <!-- 配置servlet -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <!-- 
          加载web.xml文件 
          contextConfigLocation为固定格式    
          classpath:springmvc.xml 为实际存放位置
       -->
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <!-- 表示servlet容器启动的顺序,1表示高优先级 -->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!-- 配置 servlet和URL的映射路径-->
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
View Code

相关文章:

  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案