Fóruns: Open Discussion (Thread #36776)

PDFをブラウザウィンドウ画面に表示させる方法について (2015-05-18 06:53 by TERASOLUNAの勉強者 #76134)

お世話になっております。

■「tutorial-thin」を使用して、PDFをブラウザウィンドウに表示させたいのですが、
どのように実装すればいいのか分かりません。
ご教授いただけないでしょうか。

■関係あるか分かりませんが、以下の方法を見つけていますが、実装方法が分かりません。
方法1.https://terasolunaorg.github.io/guideline/public_review/ArchitectureInDetail/FileDownload.html
方法2.参考PDF「WD-03 ファイルダウンロード機能」

■以下のような実装イメージを持っています。
[list.jsp]
<ts:link page="/userManager/downloadBL">Download</ts:link>

[userManagerContext.xml]
<bean name="/userManager/downloadBL" scope="singleton"
class="jp.terasoluna.fw.web.struts.actions.DownloadBLogicAction">
<property name="businessLogic" ref="downloadBLogic"/>
</bean>
<bean id="downloadBLogic"
class="jp.terasoluna.thin.tutorial.web.usermanager.blogic.DownloadBLogic" scope="singleton"/>

[struts-userManager-config.xml]
<action path="/userManager/downloadBL"
name="_downloadForm"
validate="true"
scope="session"
input="/logon/menu.jsp"/>

[SampleAction]
public class SampleAction extends DownloadAction {を実装し、JasperReoprtsを使用したpdfをブラウザ表示。


以上よろしくお願いします。

Responder a #76134×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: PDFをブラウザウィンドウ画面に表示させる方法について (2015-05-18 17:27 by TERASOLUNAの勉強者 #76151)

[メッセージ #76134 への返信]
ファイルのダウンロードはできるようになりました。

■struts-userManager-config.xml
<action path="/download/downloadAction"
name="_downloadForm"
validate="true"
scope="session"
input="/download/download.jsp"/>

■userManagerContext.xml
<bean name="/download/downloadAction"
class="jp.terasoluna.fw.web.struts.actions.DownloadBLogicAction"
scope="singleton">
<property name="businessLogic" ref="downloadBLogic"/>
</bean>
<bean id="downloadBLogic"
class="jp.terasoluna.thin.tutorial.web.usermanager.blogic.DownloadBLogic" scope="singleton"/>

■list.jsp
<ts:link page="/download/downloadAction.do">Download</ts:link>

■jp.terasoluna.thin.tutorial.web.usermanager.blogic.DownloadBLogic.java
package jp.terasoluna.thin.tutorial.web.usermanager.blogic;

import java.io.File;

import jp.terasoluna.fw.service.thin.BLogic;
import jp.terasoluna.fw.service.thin.BLogicResult;
import jp.terasoluna.fw.web.struts.actions.DownloadFile;

public class DownloadBLogic implements BLogic {
public BLogicResult execute(Object arg0) {
BLogicResult result = new BLogicResult();
File file = new File("/mytutorial-thin/stylesheet/system.css");
DownloadFile downloadFile = new DownloadFile(file);
result.setResultObject(downloadFile);
return result;

// return null;
}
}

以上です。


Responder a #76134

Responder a #76151×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: PDFをブラウザウィンドウ画面に表示させる方法について (2015-05-18 18:05 by TERASOLUNAの勉強者 #76155)

[メッセージ #76134 への返信]
自己解決です。
主に、方法2.参考PDF「WD-03 ファイルダウンロード機能」資料を参考に解決しました。

こちらのやり方の方が、1.ファイルのダウンロード、2.ブラウザ表示の方法が選べるので、こちらをメインのやり方としました。

<1.ファイルダウンロード>
■struts-userManager-config.xml
<action path="/download/downloadAction"
name="_downloadForm"
validate="true"
scope="session"
input="/download/download.jsp"/>

■userManagerContext.xml
<bean name="/download/downloadAction" scope="singleton"
class="jp.terasoluna.thin.tutorial.web.usermanager.blogic.SampleAction" >
</bean>

■list.jsp
<ts:link page="/download/downloadAction.do">Download</ts:link>

■jp.terasoluna.thin.tutorial.web.usermanager.blogic.SampleAction.java
package jp.terasoluna.thin.tutorial.web.usermanager.blogic;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.terasoluna.fw.service.thin.BLogic;
import jp.terasoluna.fw.service.thin.BLogicResult;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DownloadAction;

public class SampleAction extends DownloadAction {


/*
* ファイルダウンロードの際のバッファサイズ(byte)を返す
* @see org.apache.struts.actions.DownloadAction#getBufferSize()
*/
@Override
protected int getBufferSize() {
return 1024 * 1024; // (2)
}

/*
* ダウンロード対象のストリーム情報を作成して返す
* @see org.apache.struts.actions.DownloadAction#getStreamInfo(...
*/
@Override
protected StreamInfo getStreamInfo(
ActionMapping mapping
, ActionForm form
, HttpServletRequest request
, HttpServletResponse response) throws Exception {

String fileName = "I:/205104_workspace/springTerasolunaWeb/mytutorial-thin/webapps/stylesheet/system.css";

File file = new File(fileName);
//StreamInfo streamInfo = new FileStreamInfo("application/pdf", file); // (3)
StreamInfo streamInfo = new FileStreamInfo("text/html", file); // (3)

// ブラウザにインライン
response.setHeader("Content-disposition",
"inline; filename=" + fileName);
// ダウンロード選択
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);

return streamInfo;
}

}

<2.ブラウザ表示>
上記と同じ設定にする。
■jp.terasoluna.thin.tutorial.web.usermanager.blogic.SampleAction.java
の記載を以下のみとする。
response.setHeader("Content-disposition",
"inline; filename=" + fileName);

以上です。
Responder a #76134

Responder a #76155×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login