老师为什么设置Context root为/访问index.html返回404

老师为什么设置Context root为/访问index.html返回404

http://img1.sycdn.imooc.com//climg/60dd9fdb0807ba0819110871.jpg

http://img1.sycdn.imooc.com//climg/60dd9fed0836c9c819200921.jpg


http://img1.sycdn.imooc.com//climg/60dd9ffe080ccad504950461.jpg

http://img1.sycdn.imooc.com//climg/60dda0130865cc5916000855.jpg


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下就能显示出来

http://img1.sycdn.imooc.com//climg/60dda31808387a1b19170964.jpg

http://img1.sycdn.imooc.com//climg/60dda32608d4529d04810395.jpg

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,访问404跟图片路径无关,404是因为同学的项目工程中index.html外还有一层文件夹,所以直接访问index.html是访问不到的,需要添加该文件夹

http://img1.sycdn.imooc.com//climg/60de73c209e64a7f03420394.jpg

而将index.html移到WebContent目录下访问时就可以找到对应的index.html了

祝学习愉快~

  • 慕函数4309305 提问者 #1

    老师,为什么WebContent/index.html可以访问,WebContent/desktop/index.html就不可以啊

    2021-07-02 10:45:46
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码