【问题标题】:Why does "../folder/image.jpg" work when the particular jsp is only run using 'right-click-> run on server'为什么“../folder/image.jpg”在仅使用“右键单击->在服务器上运行”运行特定 jsp 时起作用
【发布时间】:2016-01-13 11:29:47
【问题描述】:
我在 Eclipse 中的文件夹设置如下:
我已将 web.xml 配置为打开欢迎文件
<welcome-file>jsp/index.jsp</welcome-file>
链接,例如 <img src="../images/image.jpg"/> 在我这样运行时工作正常:
即。单击单个 jsp 并在服务器上运行。
但是当我在服务器上运行整个项目时,没有链接工作(图像、脚本、css 没有工作)
试过jsp/index.jsp,${pageContext.request.contextPath},但找不到解决办法。帮助将不胜感激。 :( :(
【问题讨论】:
标签:
java
eclipse
jsp
web.xml
welcome-file
【解决方案1】:
纯粹是因为页面没有被解析和重新格式化,直到它通过服务器和jsp内容并被处理。
当然,大多数浏览器不会尝试“聪明”地处理事物和“自动外观”,因为它“事物”“可能”类似于 HTML/whateverML
一旦你通过服务器运行了 JSP,然后:
1) reads the xml and gets a bearing as to where it's "root is" i.e. / of you might be / on the hard drive whereas / for the web server could be /some/path/to/your/documents
2) reads the jsp page, parses, processes and executes whatever is in there. Usually per default TomCat (if thats what you're using) returns most output as HTML to the remote browser.
这就是图像工作的原因...当它从服务器返回时,它被视为“HTML 的一部分”。