包括一些返回 401 的页面

发布于 2024-10-16 05:58:59 字数 515 浏览 4 评论 0原文

我在某些服务器上部署了一些网页,

会显示: http://myhost/some_secured_file.html

当我访问此网页时, 在浏览器中打开文件时,它会返回 401,要求我授权自己。

问题是我试图使用 c:import 标记将此页面包含在某些 JSP 页面中。

应用程序服务器返回:

javax.servlet.jsp.JspException: Problem accessing the absolute URL "http://myhost/some_secured_file.html". java
    .io.IOException: Server returned HTTP response code: 401 for URL: http://myhost/some_secured_file.html

我如何完成包含!?

I've some web page deployed at some server say:

http://myhost/some_secured_file.html

when I access this file within a browser it returns 401 asking me to authorize myself.

The problem is that I am trying to include this page inside some JSP page using the c:import tag.

The app server returns :

javax.servlet.jsp.JspException: Problem accessing the absolute URL "http://myhost/some_secured_file.html". java
    .io.IOException: Server returned HTTP response code: 401 for URL: http://myhost/some_secured_file.html

How I can accomplish the include!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-10-23 05:58:59

考虑通过另一个 jsp 页面或 servlet 代理请求。然后让代理执行身份验证请求,例如使用 Apache HTTPClient,并让写入页面的响应内容。然后您只需在 jsp 页面上导入代理的 url 即可。

好吧,请考虑以下伪代码作为说明:

class Proxy extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws   ServletException, IOException {
        // Perform a new request to get contents from secured page
        HttpClient client = new HttpClient();
        Credentials credentials = new UsernamePasswordCredentials("user", "pass");
        client.getState().setCredentials(authScope, credentials);
        GetMethod method = new GetMethod("/secure_page.jsp");
        client.executeMethod(client.getHostConfiguration();, method);

        // write result to the outputstream
        resp.getWriter().write( method.getResponseBodyAsString() );
    }
}

此 servlet 的作用是为您获取受保护的页面。您需要将此 servlet 连接到您的 Web 描述符中。这是将例如 /proxy.jsp 请求映射到它所必需的。然后您可以在 jsp 页面中执行类似 的操作。

Consider proxying the request through another jsp page or servlet. Then you let the proxy perform an authenticating request, e.g., using Apache HTTPClient, and have the contents of that response written to the page. Then you can simply import the url of your proxy on your jsp page.

Alright, consider the following pseudo code as clarification:

class Proxy extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws   ServletException, IOException {
        // Perform a new request to get contents from secured page
        HttpClient client = new HttpClient();
        Credentials credentials = new UsernamePasswordCredentials("user", "pass");
        client.getState().setCredentials(authScope, credentials);
        GetMethod method = new GetMethod("/secure_page.jsp");
        client.executeMethod(client.getHostConfiguration();, method);

        // write result to the outputstream
        resp.getWriter().write( method.getResponseBodyAsString() );
    }
}

What this servlet does is fetch the secured page for you. You need to hook this servlet up in your web descriptor. This is necessary to map e.g., /proxy.jsp request to it. What you then can do in your jsp page is something like <c:import value="proxy.jsp"/>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文