• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

downloading a file struts2

 
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to download a txt file and i am getting an error

java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [fileInputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:217

Below is the code in action Class



In Struts.xml





In Jsp



Anyone please help.

thanks
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why you use:

# HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
# String filename =request.getParameter("userImageFileName");
# int id =Integer.parseInt(request.getParameter("id"));

when the easy way to do this is only creating an attribute in action with a getter, and setter if you need it, with the same name that you have in the jsp:

# <s:param name="userImageFileName" value="%{userImageFileName}"></s:param> <--
# <s:param name="id" value="%{id}"></s:param></s:url> <--
# <s:a href="%{fileDownload}"><s:property value="userImageFileName" /></s:a>

<s:a href="%{fileDownload}?userImageFileName=<s:property value="userImageFileName" />&id=<s:property value="id" />">

OR

<s:a href="%{fileDownload}?userImageFileName=document.getElementsByName('userImageFileName')[0].value&id=document.getElementsByName('id')[0].value"><s:property value="userImageFileName" /></s:a>


I hope that it was useful for you.
 
Vallaru smitha
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fres.

Eventhou I write as you mentiond i still get the same error.

java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [fileInputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:217
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post whole error stack?

I want see where you get java.lang.IllegalArgumentException.

You might get java.io.InputStream because of previous error.
as there is IllegalArgumentException, your inputName may not get initialize
 
Vallaru smitha
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing is log apart from this

rror invoking Action using Hibernate Core Session / Transaction injection
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [fileInputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:217)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
at com.googlecode.s2hibernate.struts2.plugin.s2hibernatevalidator.interceptor.HibernateValidatorIn


could anyone please help, I am kind of stuck.

Thanks
vallaru
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to verify, that code in the action class that you have, that is from com.vaannila.web.UsersAction, right? How is that "download" method getting called? And are you sure it is getting called? Can you check to see if getFileInputStream ever gets called after your action finishes, with some logging or debugging or something?
 
Vallaru smitha
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah its in my UserAction.java




this method is called when the image hyperlink is clicked on the jsp



yes getinputstream is getting called but its null. once the action finishes and then its throwing an error

Thanks


 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you verify that they download method is being called? Did you see "inside download" in your log file? The reason I'm stuck on this is I don't see anything in your code that would cause struts2 to call a method on the action other than the default of "execute()". If getFileInputStream() is getting called but its returning null, then it sounds like either the code in your "download" method isn't setting fileInputStream or else something else is nulling it back out. Perhaps you should put in some logging just before you return SUCCESS to call the getter and right to your log wheter or not the input stream is null.
 
Vallaru smitha
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom,

JSP
<

The aove code is in my jsp which puts a hyperlink on userImageFileName. When I click on the hyperlink it calls the action download. The actionclass is configured in struts.xml.

I am not clear why you feel it is not getting called.


Thanks
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, it will go to your "download" action that you have set up in your struts.xml file. From what I see in your struts.xml file, it looks like it will call the default method on your action class, which is execute. There are a few ways that I have heard of that cause struts2 to call a method other than the default one, but I don't see anything here that would make it use a method other than execute (maybe I'm just missing it).

Can you let me know how you think struts2 knows to call download and if the output from it is being written to your log file? If download isn't getting called I think that would explain your problem.
 
Girish Wakure
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Tom..
I doubt (as tom says) default execute method is being called.
 
Vallaru smitha
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

sorry for wasting your time. That was real stupidity.
I was not calling the method in xml. Thanks for pointing it out.


One last question on it , is there a limit how many files we can upload.
we have 1 excel sheet and 3 images.


 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To my knowledge there is no limit on the number of files you can uplaod. There is a maximum size restriction, I think its around 2g. You can lower that limit with the maximumSize parameter of the fileUpload interceptor.
 
reply
    Bookmark Topic Watch Topic
  • New Topic