1.${pageContext.request.contextPath}是JSP取得绝对路径的方法,等价于<%=request.getContextPath()%> 。为了防止修改项目名后找不到绝对路径所以在jsp文件的{from action} 中要添加${pageContext.request.contextPath}。
2.
因此在Controller或者pojo层多个@REquestMapping不需要进行注释只需要在浏览器网址后输入跳转文件名称即可,类如
3.两个风格格式
4.解决SpringMVC无法访问到静态资源的3种方法
(比如:No mapping for GET /js/jquery-3.3.1.min.js这种报错)
5.防止中文乱码
6.在SpringMVC框架中使用JQuery
如果你的外部资源中有JQuery那你只需要这样添加路径即可
<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
如果你没有 就在src直接加入网址,加入后记得在idea点击链接让它下载版本
JQuery的各个版本网站各版本JQuery.js合集_程序员人生
加入成功的外部库是有jQuery的。
7.解决Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is (这里是包名)] with root cause这种报错
在@RequestMapping的上面加一个@ResponseBody,在这里有几个@RequestMapping就加几个
@ResponseBody就可以解决了。
8.Tomcat报错严重: Unable to process Jar entry [module-info.class****\!] from Jar
WEB-INF下的lib中找到对应的jar包,删除module-info.class即可。
9.最后我建议SpringMVC使用Tomcat8这样可以解决大多数版本过低的问题
比如说Tomcat报ClassFormatException: Invalid byte tag in constant pool: 19的问题。
Tomcat8的pom文件配置方法如下
<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>
运行使用tomcat8:run-war运行
记得修改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>