Struts2-Streaming Video From Byte Array using struts2 - struts2

I am just a beginner in Struts2,
I want to display the videos,images in my JSP and I am able to get list of all images, videos from database as byte array list,when i tried to display 1 image or video this is what happening..any suggestion..for display list of images(<img> tag) and video(flash player)??how to achieve this :)
(1)i tried this,result in(screen shot)
image=get.loadImage();
setVideo_Content(new ByteArrayInputStream (image));
browser is asking me to download...the content :(
If I use this code..
//response.getOutputStream().write(image);
//response.getOutputStream().flush();
the image is taking the whole page..cant able to display within image tag..
struts xml
<result name="success" type="stream">
<param name="contentType">${yourContentType}</param>
<param name="inputName">Video_Content</param>
<param name="contentDisposition">attachment;filename="${yourFileName}"</param>
<param name="bufferSize">1024</param>

This :
<param name="contentDisposition">attachment;filename="${yourFileName}"</param>
is telling it to download the file. Change it to :
<param name="contentDisposition">inline;filename="${yourFileName}"</param>
to open it inside the browser with a plugin, when available.
Also, to prevent opening it full browser, try using an <iframe/> or similar, making the src attribute pointing to your download Action.

Related

Save as Dialogue showing up in IE and Firefox but not in Google chrome

In my struts2 application, I have to download the report based on given values. While downloading, IE and Firefox prompts for save as dialogue box. But Google chrome automatically download reports in Download folder.
I searched in Google and got answer like I need to add octect-stream to contentType header. I configured it in my struts xml. Still chrome is not prompting to show save as dialogue.
Below is my code
<action name="exportpsrdetails" class="com.action.Export_With_All">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentType">octet-stream</param>
<param name="contentDisposition">attachment;filename="ExportPsr.xls"</param>
<param name="inputName">excelStream</param> </result>
<result name="input">done.jsp</result>
<result name="login" type="redirect">login.jsp</result>
</action>
PS: I should not change settings in chrome to show save as dialogue box
I had face this and below help me. Add:
<param name="Content-Disposition">attachment;filename="ExportPsr.xls"</param>
you don't need to remove this !
<param name="contentDisposition">attachment;filename="ExportPsr.xls"</param>

ERROR: application/pdf is not a supported mime type [duplicate]

This question already has answers here:
File is not downloading from server
(3 answers)
Closed 9 years ago.
I am using Struts2 and Liferay for developing an application.
My struts.xml is as follows:
<action name="download" class="com.stp.portal.view.DownloadAction">
<result name="success" type="stream">
<param name="contentType">application/pdf</param>
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;filename="abc.pdf"</param>
<param name="bufferSize">1024</param>
</result>
</action>
I basically want to download a pdf file from the server. But I get the following error:
10:05:55,782 ERROR [Jsr168Dispatcher:38] Could not execute action
java.lang.IllegalArgumentException: application/pdf is not a supported mime type
at com.liferay.portlet.MimeResponseImpl.setContentType(MimeResponseImpl.java:159)...
Don't know how to resolve this. Would really appreciate someone's help. Really need this to be done.
Looking at the source code seems like only application/vnd.wap.xhtml+xml and text/html are allowed.
Source: http://grepcode.com/file/repo1.maven.org/maven2/com.liferay.portal/portal-impl/6.0.2/com/liferay/portlet/MimeResponseImpl.java
Put portletUrlType="resource" to the <s:url> tag which you use to create download link.
<s:url var="downloadUrl" action="download" portletUrlType="resource" />

Add a variable to my struts config result redirection

I have a page where I'm "Viewing session info" (where session in this context is a business element. Think of a session like a training session). Part of this session info is a list of files. (An example of a session file would be the sign-in sheet of all the people who attended the session.) Clicking the link at the end of the list of files will delete the file from the session via a method called `inativeateSe
In my struts config for inactivateSessionMaterial, I have the following result
<result name="success">
/secure/courses/sessions/view_session_info.jsp
</result>
But this is insufficient. It really needs to be view_session_info.jsp?sessionId=1234. How can I add that variable (session id) to the end of this? Something like
<result name="success">
/secure/courses/sessions/view_session_info.jsp?sessionId=$sessionId
</result>
Just use <param> tag inside your action for all results in this action
<action>
<param name="sessionId">${sessionId}</param>
<result>...</result>
</action>
or for specific action result.
<action>
<result>
<param name="location">...</param>
<param name="sessionId">${sessionId}</param>
</result>
</action>

struts2 jquery plugin wraps html to returned id

I am using struts2-jquery plugin in my project. I am trying to submit a form using <sj:submit> tag like this:
<sj:submit id="caseSubmit"
targets="result"
formIds="mainForm"
onCompleteTopics="caseSubmitted"
button="true"/>
The struts.xml mapping for this action is as follows:
<action name="submitAddCase" class="com.xxx.action.AddCaseAction">
<result type="json">
<param name="root">caseId</param>
</result>
</action>
The onComPleteTopics code
$.subscribe('caseSubmitted', function(event,data) {
var indexPre = event.originalEvent.request.responseText.indexOf("<pre>")+5;
var indexPreEnd = event.originalEvent.request.responseText.indexOf("</pre>");
var id = event.originalEvent.request.responseText.substring(indexPre,indexPreEnd);
$("#case_id").val(id);
});
What I want is to use the caseId returned to load some other stuff on the same page. But,
event.originalEvent.request.responseText returns caseId wrapped in pre tag like this
<pre>154000</pre>
This is how it is returned in firefox. In chrome it is returned in another form. How can I get th caseId's original value without wrapped html.
Right now I am using javascript's substring method to get the value it is not working in chrome because of a different returned format
Replace
$("#case_id").val(id);
with
$("#case_id").val($(id).html());

How do I configure Struts 2 to return a generated PDF?

<action name="trial_employee"
class="parity.action.TrialPrintEmployeeCopyAction">
<result>/protected/trial_employee.pdf</result>
</action>
I've got an action class that generates a PDF file for download. How do I configure the action result to return the PDF?
The above doesn't work, it gives me a 404 error because the pdf isn't physically on the drive, it's being generated dynamically.
If it is being generated dynamically you can return it as a stream something like
<result name="pdf File" type="stream">
<param name="contentType">${contentType}</param>
</result>
more details are here
Stream result

Resources