3

私は問題に直面している小さな Web アプリケーションに取り組んでいます。ここでは、イテレータを使用してjspページに表示しているコンテンツのリストがあります。各コンテンツには、それに関連付けられたいくつかの画像があります。それらの画像をコンテンツと一緒に表示したい。これを達成する方法。

これが私のコンテンツイテレータです。

<s:iterator value="contentList">
     <s:property value="id"/>
     <s:property value="topic"/>

このイテレータ タグ内で、最初のイテレータの「id」属性を使用して、2 番目のイテレータを動的に生成したいと考えています。「id」属性によって各コンテンツにマップされた画像のデータベーステーブルがあります。その特定のコンテンツに関連付けられた画像のリストを取得し、jsp ページに表示したいと考えています。画像は複数にすることができます。どうすればこれを達成できますか。助けてください。

イメージはファイル システムに保存され、パスはデータベースに保存されます。単一の画像を表示するために、私がやっていることは、アクションクラスのデータベースから画像パスを取得し、fileInputStream によって画像を jsp ページに渡すことです。複数の画像を表示しようとすると問題が発生します。

jsp で画像を表示するために使用されるコード

<img src="contentimage.action?contentID=<s:property value="id"/>"/>

<s:property value="id"/>、コンテンツ イテレータで使用できる値です。

そしてアクションクラスでは

Image ImageObject=cd.getImageObject(contentID);
File file = new  File(ImageObject.getFilePath()+"/"+ImageObject.getFileName());         
FileInputStream fileInputStream = new FileInputStream(file);

Image、ファイル システム内の FilePath や画像ファイル名などの画像属性を持つ Bean クラスです。特定の に対してcontentID、データベース内に複数の画像があり、すべて異なるファイル名とファイルパスを持つ場合があります。Imageタイプのリストでそれらを取得できます。次に、jsp ページでそれらを反復処理し、それらのパスの画像を表示する方法を説明します。今回は私の質問を明確にしています。

編集

Hibernate にマップされている私のコンテンツ クラス。

private int id;
private String topic;
//getters and Setters

Hibernate にマップされている私の ContentImage クラス。

private int contentId; // this is the id of the Content class
private String fileName; //image file name
private String filePath; // image file path, actual file is stored in file system
private String imageByte; //Base64 string of the image file
//getters and setters

ここで、ビュー jsp をロードする前のアクション クラスで、コンテンツ リストを取得します。

contentList=//got the list here;

イテレータを使用してjspに表示します。

<s:iterator value="contentList">
   <s:property value="id"/>
   <s:property value="topic"/>
   Now here i want a second iterator of my ContentImage class having a list of images corresponding to the id value of the contentList iterator.
   //This is where i am having the problem. I can display single image with this:
  <img src="contentimage.action?contentID=<s:property value="id"/>"/> //But i need to display all the images associated with this id.

   So i need an iterator created dynamically here with the id attribute and then display the images. Like:
   <s:iterator value="contentImageList">
      <img src="displayimage.action?filepath=<s:property value="filePath"/>"/>
   </s:iterator>
  </s:iterator>

2 番目のイテレータを作成できません。これを手伝ってください。

4

1 に答える 1