Recent work requires quick understanding spring mvcFramework So I found a lot of related courses on the internet. To be honest, Baidu basically comes out the same, but I have encountered all kinds of strange problems. Of course, when I look back, I find that those problems are not problems. Ha ha ha ha ~I still don't understand them. Java These things, when encountering problems, will feel difficult, various checks, but Baidu's results are very helpless, different websites, the same content!
I referred to a blog to build the project. The website is http://limingnihao.iteye.com/blog/830409. The project was created according to the process of this blog, but there are still some differences between them due to the actual situation.
Next, I will list the relevant software versions that I use. Although I don't know what the relationship is, I'd like to list them.
Ha ha ha ~ ~


Because I don't know which ones to list, I cut them all up.
Only know to use jdk, maven, tomcat, and java compilers (such as eclipse)
Start building projects now
1. Create a maven project

Figure 1

Figure 2

Figure 3 (The first check box must be a box, anyway I'm wrong if I don't choose it here ~)

Figure 4 (Packaging selects war). Anyway, I had a problem choosing jar before.

Figure 5 (The red box does not show what I want, need to be modified, right-click it, select "Build Path"=> "Configure Build Path")

Figure 6

Figure 7 (I don't know why I chose this, but I just saw my colleagues choose this before).

Figure 8

Figure 9
At this point, a mave project has been built. Now let's configure something.
2. Configure pom.xml (you can add it directly to pom.xml and configure something seven or eight. junit, jstl, spring package)
-
<dependencies>
-
-
<dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<version>4.12-beta-3</version>
-
<scope>test</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>log4j</groupId>
-
<artifactId>log4j</artifactId>
-
<version>1.2.17</version>
-
</dependency>
-
-
<dependency>
-
<groupId>jstl</groupId>
-
<artifactId>jstl</artifactId>
-
<version>1.2</version>
-
</dependency>
-
-
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-core</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-expression</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-beans</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-aop</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-context</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-context-support</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-tx</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-web</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-jdbc</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-webmvc</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-aspects</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-test</artifactId>
-
<version>4.1.2.RELEASE</version>
-
</dependency>
-
-
</dependencies>
3. Add a folder "WEB-INF" under webapp and a file "web.xml" under the folder (the following can be copied all over)
-
<?xml version="1.0" encoding="UTF-8"?>
-
<web-app 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"
-
version="2.5">
-
-
<context-param>
-
<param-name>webAppRootKey</param-name>
-
<param-value>maven.example.root</param-value>
-
</context-param>
-
-
-
<listener>
-
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
-
</listener>
-
-
-
<filter>
-
<filter-name>CharacterEncodingFilter</filter-name>
-
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
-
<init-param>
-
<param-name>encoding</param-name>
-
<param-value>UTF-8</param-value>
-
</init-param>
-
<init-param>
-
<param-name>forceEncoding</param-name>
-
<param-value>true</param-value>
-
</init-param>
-
</filter>
-
<filter-mapping>
-
<filter-name>CharacterEncodingFilter</filter-name>
-
<url-pattern>/*</url-pattern>
-
</filter-mapping>
-
-
-
<servlet>
-
<servlet-name>dispatcher0121</servlet-name>
-
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
-
<init-param>
-
<param-name>contextConfigLocation</param-name>
-
<param-value>/WEB-INF/dispatcher0121-servlet.xml</param-value>
-
</init-param>
-
<load-on-startup>1</load-on-startup>
-
</servlet>
-
<servlet-mapping>
-
<servlet-name>dispatcher0121</servlet-name>
-
<url-pattern>*.do</url-pattern>
-
</servlet-mapping>
-
-
</web-app>
There are several noteworthy points in the web.xml file. The red "dispatcher 0121" above can be changed to the string you want, but the three places must be the same. [servlet-name]+"-servlet.xml" is the naming rule for file names of spring configuration files.
4. Add a file "dispatcher0121-servlet.xml" under "webapp/WEB-INF/". This file is just what I said above (all can be copied to a new file)
-
<?xml version="1.0" encoding="UTF-8"?>
-
<beans xmlns="http://www.springframework.org/schema/beans"
-
xmlns:aop="http://www.springframework.org/schema/aop"
-
xmlns:context="http://www.springframework.org/schema/context"
-
xmlns:mvc="http://www.springframework.org/schema/mvc"
-
xmlns:tx="http://www.springframework.org/schema/tx"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.springframework.org/schema/aop
-
http://www.springframework.org/schema/aop/spring-aop-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
-
http://www.springframework.org/schema/mvc
-
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
-
http://www.springframework.org/schema/tx
-
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
-
-
<mvc:annotation-driven />
-
<context:component-scan base-package="example0121" />
-
-
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
-
<property name="prefix" value="/WEB-INF/views/" />
-
<property name="suffix" value=".jsp" />
-
</bean>
-
-
</beans>
The dispatcher0121-servlet.xml file also has something to note, "example0121" is the next package, the name can be arbitrary, but not all the numbers. I don't want to say that I'm just lazy with numbers, causing problems with previous projects.

Figure 10
5. Create a Controller layer test I don't know what this is. Only know how to operate)

Figure 11
According to this operation, you can add packages or classes. First, you can add classes. If you find that there is no "example0121" in the package, you can cancel it. Then you can add a package. The name of the package is "example0121". Then create a class called General Controller.

Figure 12
Then write the code as follows
-
package example0121;
-
-
import org.springframework.stereotype.Controller;
-
import org.springframework.ui.Model;
-
import org.springframework.web.bind.annotation.RequestMapping;
-
-
@Controller
-
public class GeneralController {
-
-
@RequestMapping(value="index.do")
-
public void index_jsp(Model model){
-
model.addAttribute("str0121", "Hellow world");
-
System.out.println("index.jsp");
-
}
-
}
6. Write JSP pages. Add a folder "views" under "webapp/WEB-INF/" and a file "index.jsp". This path was determined in "dispatcher0121-servlet.xml".
-
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<title>Insert title here</title>
-
</head>
-
-
<body>
-
<c:out value="${str0121}"></c:out>
-
</body>
-
</html>
At this point, you can see that your project has a red fork and a mistake has been reported, as shown in Figure 13. You have to be calm at this time. There are two ways. One is to ignore it, the other is to delete it. I chose to ignore it, because I checked the wrong information for a long time, inexplicably irritable, tried the online method, or not. Finally, I asked my colleagues, and they said, can you run it? I ran the project and found it working. Then my colleague said, ignore it. It seems like a question of verification, but it doesn't matter now. one or two?!

Figure 13
7, operation

Figure 14

Figure 15

Figure 16

Figure 17

Figure 18
Now it's time to create a project. We need to start a deep discussion.

