0

データベースから jsp ビューへの画像の読み込みに問題があります。アクションは実行されているように見えますが、途中で停止します。execute() メソッドの開始時と終了時にログに記録します。ログ ファイルでは、このメソッドの開始を確認できますが、終わりはありません。

私には行動があります:

public class ShowImageAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    private static final Log LOG = LogFactory.getLog(ShowImageAction.class);

    private int id;

    public String execute() {
        LOG.info("Enter execute()");
        MessageBean messageBean = (MessageBean) sessionParameters
                .get(SessionParameters.BANNER_EDIT);

        IFiles filesEJB = EJBLocator.getFiles();
        if (messageBean != null) {
            id = messageBean.getBannerId();
        }

        FileBean file = filesEJB.file(id);

        LOG.info("Id = " + id);
        if (file != null) {
            byte[] bytes = null;
            try {
                LOG.info("File: name = " + file.getName() + ". type = "
                        + file.getType());
                if (file.getImage() != null) {
                    bytes = FileUtils.readFileToByteArray(file.getImage());
                    HttpServletResponse response = ServletActionContext
                            .getResponse();
                    response.setContentType(file.getType());
                    OutputStream out = response.getOutputStream();
                    out.write(bytes);
                    out.close();
                } else {
                    LOG.info("execute(): Nie udało się pobrać pliku z bazy danych!");
                }
            } catch (IOException e) {
                LOG.error(e);
            }
        } else {
            LOG.info("execute(): Nie udało się pobrać pliku z bazy danych!");
        }
        LOG.info("Exit execute()");
        return NONE;
    }

jsp:

    <div class="OneFilteringRow">
        Podgląd<br />
        <img src="/ebok-bm/ShowImageAction" alt="Podgląd banera" />
    </div>

struts.xml

    <action name="ShowImageAction"
            class="pl.bm.action.content.ShowImageAction">
    </action>
4

2 に答える 2

0

独自の結果に切り替えて、Result クラスを実装し、ここに出力を書き込みます。その他のstruts.xmlアクションの結果の種類は、近似メイト パラメーターを使用して独自に指定します。refer:アクションの結果として自分の画像を生成する

于 2012-07-27T13:08:07.273 に答える
0

問題は次の場所にありました:

FileBean file = filesEJB.file(id);

データベースからバイトを取得し、tmpFile に保存しようとしました。今、バイトを取得して一時ファイルに書き込み、すぐにアクションに送信すると、すべて問題ありません。今私が持っています:

    FileBean file = filesEJB.file(id);

    LOG.info("Id = " + id);
    if (file != null) {
        byte[] bytes = null;
        try {
            LOG.info("File: name = " + file.getName() + ". type = "
                    + file.getType());
            if (file.getImage() != null) {
                **bytes = file.getImage();**
                HttpServletResponse response = ServletActionContext
                        .getResponse();
                response.setContentType(file.getType());
                OutputStream out = response.getOutputStream();
                out.write(bytes);
                out.close();
            } else {
                LOG.info("execute(): Nie udało się pobrać pliku z bazy danych!");
            }
        } catch (IOException e) {
            LOG.error(e);
        }
    }
于 2012-07-27T10:22:47.420 に答える