我已将 web.xml 配置为打开欢迎文件
<welcome-file>jsp/index.jsp</welcome-file>
链接,例如<img src="../images/image.jpg"/>
当我像这样运行时工作正常:
即,。单击单个 jsp 并在服务器上运行。
但是当我在服务器上运行整个项目时,没有链接起作用(图像、脚本、CSS 不起作用)
尝试过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/