轉自:http://blog.csdn.net/sapphire_aling/article/details/6715448
今天實現文件下載功能,照着網上的代碼寫了,結果總是提示下面的錯誤:
Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
這個錯誤,這個錯誤網上的解釋都是正確的,就是輸入流得到的是空
網上的得到輸入流都是用這句話實現: inputStream=ServletActionContext.getServletContext().getResourceAsStream(realPath);
這裏正常解釋是相對路徑realPath要以/開頭,而且要下載的文件要位於Webcontent目錄下
不過在我這裏就是行不通
因此我放棄了相對路徑,改成絕度路徑實現
String realPath = "d:\\Aggressive\\" + uploadFileName;
File file = new File(realPath);
inputStream = new FileInputStream(file);
這樣就可以了
希望對有同樣問題的朋友能有個幫助