初学spring MVC,上周用Eclipse写Hello World遇到的问题回顾。
问题1:
spring MVC的Controller中使用ModelAndView传数据给前端,${message} jsp接收不到
原因:maven创建项目自动生成的web.xml问题
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
...
</web-app>
解决办法:修改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_4_0.xsd"
version="4.0">
...
</web-app>
问题2:servlet.jsp中xsi:schemaLocation中"...http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd" 显示文件下载无法写入报错。
完整报错信息:Error while downloading 'http://www.springframework.org/schema/context//spring-context-4.3.xsd' to C:\...\.lemminx\cache\http\www.springframework.org\schema\context\spring-context-4.3.xsd
解决过程:
第一步:检查网址 http://www.springframework.org/schema/context/有spring-context-4.3.xsd,而且电脑网络没问题,应该不是不能下载的问题;
第二步:检查 C:\...\.lemminx\cache\http\www.springframework.org\schema\context\目录,发现 C:\...\.lemminx\cache\http\www.springframework.org\schema\下只有beans文件夹,没有context文件夹;
第三步:于是从第一步的网址上手动下载.xsd文件,再手动在C:\...\.lemminx\cache\http\www.springframework.org\schema\创建context文件夹,最后把手动下载的.xsd文件放到文件夹中。
问题是解决了,到底啥原因还是不知道。