【发布时间】:2015-05-13 11:27:35
【问题描述】:
过去,我们使用 SSO 解决方案进行身份验证。 servlet 过滤器正在检查登录等。 为了降低成本,我们希望用针对我们数据库的简单身份验证来替换它。
这里的计划是使用旧的登录/密码更改 jsp(位于 sso 服务器上)并以这种方式直接在我们的应用程序中调用它(如果过滤器检测到未登录的用户):
req.getRequestDispatcher("/auth/login.jsp").include(req, response);
页面被显示,但只有文本。不显示图像和样式表。 (找不到)。
<img src="/auth/platform.jpg" alt="platform" class="left" />
我尝试了其他几种方法,但所有这些版本都不起作用。我知道,相对路径行不通!
<img src="auth/platform.jpg" />
<img src=".auth/platform.jpg" />
<img src="<%=request.getContextPath()%>/auth/platform.jpg" />
我输出了以下内容,一切都是空的。
ServletPath: <%request.getServletPath(); %> <br />
ServletContext: <%request.getServletContext();%> <br />
ContextPath: <%request.getContextPath(); %> <br />
LocalAddr: <%request.getLocalAddr(); %> <br />
PathInfo: <%request.getPathInfo(); %> <br />
RemoteAddr: <%request.getRemoteAddr(); %> <br />
RemoteHost: <%request.getRemoteHost(); %> <br />
在原始项目(登录页面所在的项目)中,jsp 仅如下所示:
<img src="images/platform.jpg" />
它可以工作,也可以使用相对引用...
通过以这种方式(或上述任何其他方式)引用它也无法找到样式表:
<link href="/auth/style.css" rel="stylesheet" type="text/css" />
但如果我使用这种方式,它就可以工作!
<style>
<%@ include file="/auth/style.css"%>
</style>
这是我的结构:
我的 web.xml 中是否还需要其他任何内容?
我知道,现在会使用 JSF,但这是一个老项目,应该尽可能少修改。
这是http错误信息:
ERROR] 500 - GET /auth/platform.jpg (127.0.0.1) 2720 bytes
Request headers
Host: localhost:8888
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:8888/Application.html?gwt.codesvr=127.0.0.1:9997&groupId=xxx
Cookie: JSESSIONID=b56c92nn81g51d28ys2l65dg2
Connection: keep-alive
Response headers
Accept-Ranges: bytes
Content-Type: text/html
Content-Length: 2720
Last-Modified: Thu, 30 Apr 2015 11:43:38 GMT
【问题讨论】:
-
如果您发布应用程序的图片(文件夹结构),将很容易回答。
-
此外,您为这些文件获取的 HTTP 状态代码也会有所帮助。
-
你的应用的上下文路径是什么?
-
在粘贴错误消息时,我看到了以下内容:Accept: image/png,image
-
你想在
login.jsp处显示platform.jpg吗?