First Hair exception
Can not find a java.io.InputStream with the name [DownloadFile] in the invocation stack. Check the <param name= "InputName" > tag specified for this action
This exception is because the input stream configured in Sturts.xml is not found or is not available, or null, in short, is not obtained, because I get the stream in action is not the correct path to write, resulting in not getting to the stream, changed the path is OK!
Get file stream in action
// download required streams for attachments Public throws exception{
This gets the stream bit null, which is estimated to be an incorrect path write //return Servletactioncontext.getservletcontext (). getResourceAsStream ("C:/users/administrator/desktop/test.txt"); New File ("C:/users/administrator/desktop/test.txt"); New FileInputStream (f); return stream; }
Next attention!
Look at the getResourceAsStream:
Usage of getResourceAsStream in Java
First, there are several getresourceasstream in Java:
1. Class.getresourceasstream (String Path): path does not start with '/' by default when the resource is taken from the package in which the class is located, and the '/' begins with the
Classpath under Root. It only constructs an absolute path through path, and eventually it gets the resources from the ClassLoader.
2. Class.getClassLoader.getResourceAsStream (String path): By default is obtained from the classpath root, path cannot start with '/' and is ultimately determined by
ClassLoader get resources.
3. ServletContext. getResourceAsStream (String path): The default is to fetch resources from the WebApp root directory, whether or not tomcat under path begins with '/'.
Of course, this is related to specific container implementations.
4. The application built-in object under JSP is an implementation of the above ServletContext.
Second, getResourceAsStream usage is roughly the following:
First: The file to be loaded and the. class file are in the same directory, for example: Com.x.y has a class me.class, and a resource file Myfile.xml
Then, you should have the following code:
Me.class.getResourceAsStream ("Myfile.xml");
Second: In the subdirectory of the Me.class directory, for example: Com.x.y under the class Me.class, while the Com.x.y.file directory has a resource file Myfile.xml
Then, you should have the following code:
Me.class.getResourceAsStream ("File/myfile.xml");
Third: Not under the Me.class directory, also not under the subdirectory, for example: Com.x.y under the class Me.class, while in the Com.x.file directory has a resource file Myfile.xml
Then, you should have the following code:
Me.class.getResourceAsStream ("/com/x/file/myfile.xml");
To summarize, maybe it's just two ways of writing
First: There is "/" in front
"/" represents the root of the project, such as the project name MyProject, "/" represents the MyProject
Me.class.getResourceAsStream ("/com/x/file/myfile.xml");
Second: There is no "/" in front
Directory representing the current class
Me.class.getResourceAsStream ("Myfile.xml");
Me.class.getResourceAsStream ("File/myfile.xml");
Disclaimer: Blue Font part reprinted from: http://www.cnblogs.com/javayuer/archive/2011/01/02/1924192.html
Struts2 file download cannot find an input stream exception