jsp上不显示图形
在我的应用程序中,jsps 文件夹中的所有 jsp 页面 我在index.jsp中给出路径:<% response.sendRedirect(response.encodeRedirectURL("/项目名称/jsps/main.jsp")); %>
虽然 main.jsp 已显示,但它不显示徽标、图形等。 js 文件夹中的所有 js 和徽标文件与 jsps 和 WEB-INF 文件夹平行。 现在的结构是: ProjectName>WebContent>Company1,WEB-INF,index.jsp,jsps>此处
Company1 文件夹中的所有 jsp 都有一些 CSS 文件。但未显示图形。当所有 jsp 都在 Company1 文件夹中时它工作正常。
in my application all jsp pages in jsps folder
i give the path in index.jsp:<%
response.sendRedirect(response.encodeRedirectURL("/Projectname/jsps/main.jsp"));
%>
although main.jsp is show but it does not show logo, graphics etc.
all the js and logo files in js folder which is parallel to jsps and WEB-INF folders.
now structure is:
ProjectName>WebContent>Company1,WEB-INF,index.jsp,jsps>here all jsp's
in Company1 folder having some CSS file.but graphics are not shown. it work fine when all jsp's was in Company1 folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所说的“图形”(图像、CSS 等)不会加载到网络服务器中,而是通过简单的 HTTP 请求加载到网络浏览器中。相对 URL 是相对于当前请求 URL(如您在浏览器地址栏中看到的),而不是相对于服务器端的文件夹结构。
为了计算出正确的相对 URL,您需要知道 JSP 页面和图像文件的绝对 URL。例如 http://example.com/jsps/page.jsp 和 http://example.com/images/image.gif。在这种情况下,图像的相对 URL(与 JSP 页面相反)将是上一个文件夹,然后是文件名:
../images/image.gif
或者,您也可以使用域相对URL,以前导斜杠开头:/images/image.gif
。如果您使用 CSS 背景图像,例如
selector { background: url('foo.gif'); }
,那么您需要知道这些 URL 是相对于 CSS 文件本身的 URL,而不是相对于包含 CSS 文件的 JSP 页面。如果您无法让它工作,请更新您的问题以包含 JSP 页面和图像文件的绝对 URL,然后我们可以帮助您提取正确的相对 URL。
"Graphics" as you call it (images, CSS, etc), are not loaded in webserver, but in webbrowser by a simple HTTP request. Relative URL's are relative to the current request URL (as you see in browser address bar), not to the folder structure in the server side.
In order to figure the correct relative URL, you need to know the absolute URL of both the JSP page and the image file. For example http://example.com/jsps/page.jsp and http://example.com/images/image.gif. In that case, the relative URL to the image as opposed from the JSP page would be one folder up and then the filename:
../images/image.gif
Alternatively you can also use a domain-relative URL, starting with a leading slash:/images/image.gif
.If you're using CSS background images like
selector { background: url('foo.gif'); }
, then you need to know that those URL's are relative to the URL of the CSS file itself, not to the JSP page which is including the CSS file.If you can't get it to work, update your question to include the absolute URL of both the JSP page and the image file, then we can assist you in extracting the correct relative URL.