別の jsp ページまたはサーブレットを介して要求をプロキシすることを検討してください。次に、たとえば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() );
}
}
このサーブレットが行うことは、保護されたページを取得することです。このサーブレットを Web ディスクリプタに接続する必要があります。/proxy.jspこれは、リクエストなどをマッピングするために必要です。jsp ページでできることは、次のようなもの<c:import value="proxy.jsp"/>です。