Overview
IntelliJ idea is a more integrated and intelligent development tool, relatively more convenient to use relative to myeclipse development, the initial manual use idea to build the Spring MVC project, the operation process is now organized as follows.
Environment content is as follows: Idea version 2017.2.4 tomcat version tomcat 8.5.13 JDK version 1.8
Operation Flow
1. Select Spirng-->spring MVC after selecting next
2, enter the project name, click Finish, complete the project fight
3, put Commons-logging-1.1.1.jar, jstl-1.2, standard-1.1.2 into the Lib directory. These 3 package files are of great importance, Commons-logging-1.1.1.jar is primarily compatible with TOMCAT8, and now the Commons-logging-1.2.jar is referenced in Tomcat8 with a problem, always prompting not FIND Error message for Exception log. jstl-1.2, standard-1.1.2 is mainly used to parse the servlet file information in the controller under MVC;
4. Select File->project structure or press the shortcut key (Shift+ctrl+alt+s) to open the configuration page. Find libraries, select Spring-4.3.10 releas, click + Sign, add the three jar packages just copied to the current Lib
5, select File->project structure or press the shortcut key (shift+ctrl+alt+s), open the configuration page to find artifacts, the class package published to the output directory lib;
6. Modify the Web. xml file to modify the Url-pattern match as follows:
<?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"> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /web-inf/applicationcontext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet -class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet- Name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
Modify the Dispatcher-servlet.xml content as follows:
<?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.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC
Http://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scanBase-package="com.dben.controllers"/><mvc:annotation-driven/> <MVC:default-servlet-handler/> <!--viewresolver View Parser--<!--to support Servlet, JSP view resolution--<bean id="Jspviewresolver" class="Org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="Viewclass"Value="Org.springframework.web.servlet.view.JstlView"/> <property name="prefix"Value="/web-inf/views/"/> <property name="suffix"Value=". JSP"/> </bean></beans>
7, in Web-inf New folder views, in this directory, the new hindex.jsp file;
8, in the SRC directory, the new package com.dben.controllers, under the package to create a new class file Hellocontroller is the so-called controller;
Package Com.dben.controllers;import Org.springframework.stereotype.controller;import Org.springframework.ui.model;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.RequestMethod; @Controller Public classhellocontroller{@RequestMapping (value="/hindex", method =requestmethod.get) PublicString Printhello (model model) {Model.addattribute ("MSG","Spring MVC HELLO"); return "Hindex"; }}
9. Configuring Tomcat
9.1 Find Edit Configurations
9.2. Add Tomcat
9.3. Find Tomcat8, configure project content items
9.4, select the appropriate deployment, configure the appropriate items:
Set Application Context Value
10, run Tomcat can, browser input: Http://localhost:8080/HCB/HIndex, display the corresponding page content. To this configuration complete
Package file Download
Commons-logging-1.1.1.jar Jstl-1.2.jar Standard-1.1.2.jar
Idea creates a spring MVC project build