- PR -

Tomcat5 FORM認証について

1
投稿者投稿内容
みーちく
大ベテラン
会議室デビュー日: 2002/08/29
投稿数: 131
投稿日時: 2005-04-27 14:38
こんにちわ。
みーちくと申します。
よろしくお願いいたします。

現在Eclipse3でデモプログラムを作成中です。
Tomcat5のForm認証を使用しております。
http://localhost:8080/form/HTML/chap1.htmlにアクセスした場合、
認証はうまくいっているのですが、画像が表示できません。
使用している画像は、セキュリティをかけるフォルダーの外に置いてあります。
どうしても原因がつかめません。
皆様、ご教授お願い致します。

[ディレクトリ構造]
/form
├login.jsp
├err.html
 ├HTML
 │├chap1.html
 │└chap2.html
 └WEB-INF
   └web.xml

[web.xml]
コード:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Authentication of FormAuth</web-resource-name>
      <url-pattern>/HTML/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>basic</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/err.html</form-error-page>
    </form-login-config>
  </login-config>
  
  <security-role>
    <role-name>basic</role-name>
  </security-role>
</web-app> 



[login.jsp]
コード:
<%@ page contentType="text/html; charset=Shift_JIS" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
  <meta http-equiv="ImageToolBar" content="no">
  <title>ログイン画面テスト</title>
  <link rel="stylesheet" href="css/default.css" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form  action='<%= response.encodeURL("j_security_check") %>' method="post">

<a name="pagetop"></a>

<!-- ヘッダー -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td background="images/heder.gif"></td>
  </tr>
</table>

<!-- メイン -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <BR><BR><BR>
      <!-- 入力領域 -->
      <table width="230" border="0" cellpadding="0" cellspacing="0" align="center">
        <tr>
          <td class="f12h">ログインID&nbsp;</td>
          <td><input type="text" name="j_username" maxlength="15"></td>
        </tr>
        <tr>
          <td class="f12h">パスワード&nbsp;</td>
          <td><input type="password" name="j_password" maxlength="15"></td>
        </tr>
        <tr>
          <td colspan="2" align="center">
            <INPUT type="submit" value="送信">&nbsp;
            <INPUT type="reset" value="キャンセル">
          </td>
        </tr>
      </table>
      <BR><BR><BR>
    </td>
  </tr>
</table>

<!-- フッター -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td background="images/footer.gif"></td>
  </tr>
</table>
</form>
</BODY>
</HTML>

山本 裕介
ぬし
会議室デビュー日: 2003/05/22
投稿数: 2415
お住まい・勤務地: 恵比寿
投稿日時: 2005-04-27 15:45
アクセスログを確認してみてはいかがでしょう。
どのようにリクエストがとんで、どのように跳ねられてるのか確認できるかもしれません。
aa
ぬし
会議室デビュー日: 2004/01/08
投稿数: 299
投稿日時: 2005-04-27 21:05
どこに画像ファイルを置いているのか知りませんけど、web.xmlでセキュリティを設定していない状態では画像は表示されているのでしょうか?
Anthyhime
ぬし
会議室デビュー日: 2002/09/10
投稿数: 437
投稿日時: 2005-04-27 21:20
画像を絶対パスで指定してみましょう。
かつのり
ぬし
会議室デビュー日: 2004/03/18
投稿数: 2015
お住まい・勤務地: 札幌
投稿日時: 2005-04-27 21:45
パスの問題をどうしても解決できないと仰っていますが、
わからないなりに、images/heder.gifを
../images/heder.gifにしてみたり、
images/heder.gifにしてみたり等、色々試行錯誤してみましたか?
みーちく
大ベテラン
会議室デビュー日: 2002/08/29
投稿数: 131
投稿日時: 2005-04-28 11:30
みーちくです。

インギさん、aaさん、Anthyhimeさん、かつのりさん
返信ありがとうございました。
また、返事が遅くなり、申し訳ございませんでした。

いろいろ皆様のアドバイスにより、解決できました。
画像のパスが問題でした。

request.getContextPath()でドキュメントルートを取得した所、
うまくいきました。

×<td background="images/heder.gif"></td>
○<td background='<%= request.getContextPath() + "/common/images/header.gif" %>'></td>

ご教授くださいまして、ありがとうございました。
1

スキルアップ/キャリアアップ(JOB@IT)