struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tarun Chowdhry <TChowd...@ipolicynetworks.com>
Subject RE: file download issue
Date Mon, 19 Oct 2009 11:15:04 GMT
Hi Paweł,
You are absolutely right. I was getting the return stream as null. This was so because my
file name that I was passing to the getResourceAsStream(..) was not starting with a forward
slash.
The path must begin with a "/" and is interpreted as relative to the current context root.
This method returns null if no resource exists at the specified path. For example, using a
path that doesn't start with a slash, You will get a null return value from:

ServletContext.getResourceAsStream("WEB-INF/resources/yourfilename.cnf").


THANKS A LOT AGAIN.


Kind Regards,
Tarun


-----Original Message-----
From: Paweł Wielgus [mailto:poulwiel@gmail.com]
Sent: Monday, October 19, 2009 4:30 PM
To: Struts Users Mailing List
Subject: Re: file download issue

Hi Tarun,
double check that this InputStream is valid,
i have such exception when i'm downloading not existing files.

Best greetings,
Paweł Wielgus.


2009/10/19 Tarun Chowdhry <TChowdhry@ipolicynetworks.com>:
> Hi,
> Getting the following exception when trying to call the FileUpload code:
> Action class:
> import java.io.*;
> import com.opensymphony.xwork2.ActionSupport;
> import com.opensymphony.xwork2.Action;
> import org.apache.struts2.ServletActionContext;
>
>
>
>
> public class     extends ActionSupport{
>
>        private String filename;
>        public InputStream myStream;
>
>
>        public String getFilename(){
>                return filename;
>        }
>
>        public void setFilename(String u){
>                System.out.println("----------name set to " + u);
>                filename = u ;
>
>        }
>
>        public void setMyStream(InputStream i){
>                myStream = i;
>        }
>
>        public InputStream getMyStream(){
>
>                return ServletActionContext.getServletContext().getResourceAsStream(filename);
>        }
>
> }
>
> Configuration:
> <?xml version="1.0" encoding="UTF-8" ?>
>
> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
>
>
> <struts>
>
>        <constant name="struts.devMode" value="true" />
>
>
>        <package name="tarun" namespace="/" extends="struts-default">
>
>
>                <action name="filedownload">
>                        <result>filedownload.jsp</result>
>                </action>
>
>                <action name="startdownload" class="FileDownload">
>                        <result type="stream" name="success">
>                                <param name="inputName">myStream</param>
>                                <param name="contentType">application/octet-stream</param>
>                                <param name="contentDisposition">attachment;filename="lists.text"</param>
>                        </result>
>                </action>
>
>                <action name="login">
>                        <result>login.jsp</result>
>                </action>
>
>                <action name="loginSubmit" class="UserValidator">
>                        <result name="input">login.jsp</result>
>                        <result name="success">success.jsp</result>
>                </action>
>        </package>
>
> </struts>
>
>
>
>
> --------------------------------------------------------------------------------
>
> equest.
>
> exception
>
> javax.servlet.ServletException: Can not find a java.io.InputStream with the name [myStream]
in the invocation stack. Check the <param name="inputName"> tag specified for this action.
>        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
>        org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
>
>
> root cause
>
> java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name
[myStream] in the invocation stack. Check the <param name="inputName"> tag specified
for this action.
>        org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)
>        org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
>        com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
>        com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
>        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
>        org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
>        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)
>        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
>        com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>        com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>        com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>        org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
>        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
>        org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
>
>
> note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
>
>
> --------------------------------------------------------------------------------
>
> Apache Tomcat/5.5.9
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message