1、新建java工程

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

 

 2、设置项目

 intellij idea springmvc web工程之helloworld

 

 intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

 

2、添加jar包

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

 

 intellij idea springmvc web工程之helloworld

 

 3、配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <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>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

 

 

4、src下新建springmvc.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.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <!-- 配置自定扫描的包 -->
    <context:component-scan base-package="com.wangyang.controller"></context:component-scan>

    <!-- 配置视图解析器: 如何把 handler 方法返回值解析为实际的物理视图 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

</beans>

 

 

5、controller和jsp

 

intellij idea springmvc web工程之helloworld

 

 intellij idea springmvc web工程之helloworld

 

 6、配置tomcat

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

intellij idea springmvc web工程之helloworld

 

相关文章:

  • 2021-05-27
  • 2022-12-23
  • 2021-12-14
  • 2021-06-30
  • 2021-08-21
  • 2021-11-30
  • 2021-05-20
  • 2021-12-09
猜你喜欢
  • 2021-05-30
  • 2021-05-29
  • 2021-09-01
  • 2022-12-23
  • 2022-02-07
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案