java - 当特定 jsp 仅使用 "../folder/image.jpg"运行时,为什么 'right-click-> run on server' 可以工作

标签 java eclipse jsp web.xml welcome-file

我在 Eclipse 中的文件夹设置如下:

enter image description here

我已将 web.xml 配置为打开欢迎文件

<welcome-file>jsp/index.jsp</welcome-file>

链接,例如<img src="../images/image.jpg"/>当我像这样运行时工作正常:

enter image description here

即,。单击单个 jsp 并在服务器上运行。

但是当我在服务器上运行整个项目时,没有链接起作用(图像、脚本、CSS 不起作用)
enter image description here

尝试过jsp/index.jsp,${pageContext.request.contextPath} ,但无法找出解决方案。非常感谢您的帮助。 :( :(

最佳答案

纯粹是因为页面在通过服务器和 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 的一部分”。

关于java - 当特定 jsp 仅使用 "../folder/image.jpg"运行时,为什么 'right-click-> run on server' 可以工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34765521/

相关文章:

java - 记录 REST 方法调用的最佳方法是什么?

java - Dropbox API v2 中的全局光标

c - 使用 GDB 进行 Eclipse C/C++ 调试

python - 使用 eclipse 运行 Python Django migrate 时出现 Mysql 错误

java - scriptlet 内的脚本 - 不良做法如何避免

java - Struts 1 日期格式标签

java - AudioTrack - IllegalStateException : play() called on uninitialized AudioTrack

java - NativeProcess API Java 调试?

Eclipse - 如何关闭动态编译/错误检查

java - jsp中的oracle连接