老师为什么设置Context root为/访问index.html返回404
web.xml
1 | <?xml version= "1.0" encoding= "UTF-8" ?><br><web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" <br>xmlns= "http://xmlns.jcp.org/xml/ns/javaee" <br>xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" <br>id= "WebApp_ID" version= "3.1" ><br> <display-name>demo12zhou4jie3zhang1</display-name><br> <welcome-file-list><br> <welcome-file>index.html</welcome-file><br> <welcome-file>index.htm</welcome-file><br> <welcome-file>index.jsp</welcome-file><br> <welcome-file> default .html</welcome-file><br> <welcome-file> default .htm</welcome-file><br> <welcome-file> default .jsp</welcome-file><br> </welcome-file-list> <br></web-app><br> |
WebContent/desktop/index.html
1 | <!DOCTYPE html><br><html><br><head><br><meta charset= "UTF-8" ><br><title>PC page</title><br></head><br><body><br> <img alt= "PC界面图片不存在" src= "../images/desktop.jpg" /> <br></body><br></html><br> |
改成src="/images/desktop.jpg"也是一样404
WebContent/mobile/index.html
1 | <!DOCTYPE html>< br >< html >< br >< head >< br >< meta charset = "UTF-8" >< br >< title >Mobile page</ title >< br ></ head >< br >< body > < br > < img alt = "移动端界面图片不存在" src = "../images/mobile.jpg" style = "width:100%" />< br ></ body >< br ></ html >< br > |
改成src="/images/mobile.jpg"也是一样404
但是如果我把index.html放到WebContent下就能显示出来
源自:过滤器
3-1 多端设备自动适配
15
收起
正在回答
1回答
同学你好,访问404跟图片路径无关,404是因为同学的项目工程中index.html外还有一层文件夹,所以直接访问index.html是访问不到的,需要添加该文件夹
而将index.html移到WebContent目录下访问时就可以找到对应的index.html了
祝学习愉快~
相似问题
登录后可查看更多问答,登录/注册
java工程师2020版
- 参与学习 人
- 提交作业 9403 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧