Some problems with the SpringMVC framework

1. ${pageContext.request.contextPath} is the method for JSP to obtain the absolute path, which is equivalent to <%=request.getContextPath()%>. In order to prevent the absolute path from being found after modifying the project name, ${pageContext.request.contextPath} should be added in the {from action} of the jsp file.

2.

Therefore, multiple @REquestMappings in the Controller or pojo layer do not need to be annotated, just enter the name of the jump file after the browser URL, such as

 3. Two style formats

 4. Three methods to solve SpringMVC's inability to access static resources

(For example: No mapping for GET /js/jquery-3.3.1.min.js such error reporting)

 5. Prevent Chinese garbled characters

 6. Using JQuery in the Spring MVC framework

If you have JQuery in your external resources, you only need to add the path like this

<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>

If you don’t, add the URL directly in src, remember to click the link in idea to download the version after joining

 Collection of JQuery.js in various versions of JQuery website - Programmer's Life

The external library that joined the success is jQuery.

 7. Solve the error of Servlet.service() for servlet [dispatcherServlet] in context with path [] thrown exception [Request processing failed; nested exception is (here is the package name)] with root cause

Add a @ResponseBody on top of @RequestMapping, and add a few @RequestMapping here

@ResponseBody does the trick.

 8.Tomcat reports a serious error: Unable to process Jar entry [module-info.class****\! ] from Jar

Find the corresponding jar package in lib under WEB-INF and delete module-info.class.

9. Finally, I suggest that SpringMVC use Tomcat8, which can solve most of the problems of low version

For example, Tomcat reports ClassFormatException: Invalid byte tag in constant pool: 19.

The pom file configuration method of Tomcat8 is as follows

 <pluginRepositories>
    <pluginRepository>
      <id>alfresco</id>
      <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
    </pluginRepository>
  </pluginRepositories>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId> tomcat8-maven-plugin</artifactId>
        <version >3.0-r1655215</version>
        <configuration >
          <path>/</path>
          <port>8080</port>
        </configuration>
      </plugin>
    </plugins>
  </build>

Run run using tomcat8:run-war

Remember to modify the version header of web.xml


<?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_3_1.xsd"
         version="3.1">
</web-app>

Guess you like

Origin blog.csdn.net/qq_68890680/article/details/130377907