2014年1月7日星期二

struts2 file download problems Can not find a java.io.InputStream with the name [downloadFile]

Serious : Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack Check the tag specified for this action
------ Solution ----------------------- ---------------------
landlord to look inside the file uploaded to the tomcat is not no ? If the landlord restart tomcat in eclipse , then , tomcat will automatically empty the following files uploaded to the project , so you go to download it certainly is not found.
If you upload to the server immediately after the download is available for download , restart the server and then click to download it, it will report that you are wrong .

------ Solution ------------------------------------ --------
will be Chinese garbled
proposal to exclude the Chinese encoding upload path , and then testing whether there will be a similar error
------ Solution ---------------- ----------------------------
public InputStream getDownloadFile ()
{
this.setFileName ();
return ServletActionContext.getServletContext (). getResourceAsStream (
"/" + UploadConfigurationRead.getInstance () getConfigItem ("uploadFilePath") trim () + "/" + fileName)..;
}
changed :

public InputStream getDownloadFile throws FileNotFoundException () {
this.setFileName ();
File file = new File ("/" + UploadConfigurationRead.getInstance (). getConfigItem ("uploadFilePath"). trim () + "/ "+ fileName);
InputStream is = new FileInputStream (file);
return is;
}
on the line
------ For reference only -------------------------------- -------
there , ah, this is how to get the path ah
------ For reference only ---------------- -----------------------
only an error message will not solve the problem, this phenomenon can cause a lot of problems . Do you want to enumerate out of it ?
------ For reference only -------------------------------------- -




attachment; filename = "$ {fileName}"
downloadFile




public InputStream getDownloadFile ()
{

this.setFileName ();
return ServletActionContext.getServletContext (). getResourceAsStream (
"/" + UploadConfigurationRead.getInstance () getConfigItem ("uploadFilePath") trim () + "/" + fileName)..;
}
------ For reference only --------------------------------- ------
seems to be the wrong path to write , I print that is null
------ For reference only ----------------- ----------------------


file is there, if you upload to the server immediately after the download is being given ,
------ For reference only --------------- ------------------------
public class DownloadAction extends ActionSupport
{
private static final long serialVersionUID = 6329383258366253255L;
private String fileName;
private String fileRealName;

public void setFileName ()
{
/ / get a request to download a file name
String fname = ServletActionContext.getRequest () getParameter ("name").;
String frealname = ServletActionContext.getRequest () getParameter ("realName").;
try
{
/ *
* fname parameter for UTF-8 decoding NOTE: actual use of local decoding UTF-8 encoding , the machine is GBK.
* used here request.setCharacterEncoding decoding invalid.
* Only decoded getDownloadFile () method to find the correct file requests under the download directory
* /
fname = new String (fname.getBytes ("ISO-8859-1"), "UTF-8");
frealname = new String (frealname.getBytes ("ISO-8859-1"), "UTF-8");
} catch (Exception e)
{
e.printStackTrace ();
}
this.fileName = fname;
this.fileRealName = frealname;
System.out.println (fileName);
System.out.println (fileRealName);
}
/ *
* @ getFileName This method corresponds to the struts.xml file : * name = "contentDisposition"> attachment; filename = "$ {fileName}"
* This property is set in the file name to download tool to download files displayed in order to correctly display Chinese file name, we need to re- encode fileName Otherwise, the situation
* Chinese name files garbled , or can not be downloaded
* /
public String getFileName () throws UnsupportedEncodingException
{
fileRealName = new String (fileRealName.getBytes (), "ISO-8859-1");
return fileRealName;
}

/ *
* @ getDownloadFile This method corresponds to the struts.xml file : * name = "inputName"> downloadFile Return to download the file stream , you can see the source struts2
* /

public InputStream getDownloadFile ()
{
this.setFileName ();
return ServletActionContext.getServletContext (). getResourceAsStream (
"/" + UploadConfigurationRead.getInstance () getConfigItem ("uploadFilePath") trim () + "/" + fileName)..;
}
@ Override
public String execute () throws Exception
{
return SUCCESS;
}
}
------ For reference only --------------------------------- ------


is garbled, but how do I turn it was chaos, teach me how to turn it
------ For reference only ----------------- ----------------------
serious : Can not find a java.io.InputStream with the name [ downloadFile] in the invocation stack. Check the tag specified for this action.

Does anyone ah, or this problem, it is not garbled, the path can be found , there may be a problem ah ?
------ For reference only -------------------------------------- -
name path no problem , no error, it does not show how it downloads
------ For reference only --------------- ------------------------
problem solved. . . pit father . struts can not asynchronous
------ For reference only ---------------------------------- -----
Thank you, landlord , and also helped me a great favor .
------ For reference only ---------------------------------------
understand some of the very detailed explain

没有评论:

发表评论