我想用jsp將文件上傳到mysql數據庫中。當我使用input type =「file」時,jsp沒有返回完整路徑。我需要完整的路徑上傳一個文件在MySQL數據庫。我想用jsp將文件上傳到mysql數據庫
<form id="translationFormID" method="post" action="saveTranslation">
<input type="file" name="attachCV" id="attachCVID" value="Attach CV">
<input type="submit" name="submit" />
</form>
這是我的jsp頁面。我使用post方法調用servlet'saveTranslation'。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String attachCV=null;
try{
String attachCV=request.getParameter("attachCV");
System.out.println("path= "+attachCV);
}
catch(Exception){
e.printStackTrace();
}
}
這是我的servlet代碼。這裏獲取並打印attachCV參數。當我打印attachCV,它顯示類似'c:\ fakepath \ sample.docx'
繼續。你有我們的許可。:-)既然你沒有發佈任何能夠顯示你所嘗試的代碼的代碼,你的問題很可能會被關閉。這裏沒有足夠的信息來回答你的問題。僅僅使用'input type ='file''不會告訴你的服務器在哪裏存儲它,並且保存到客戶端文件夾的「完整路徑」(這是設置'輸入類型'可用的設置)在服務器上是沒有意義的。 –
請給出一些建議。 –
如果您不再重新發布相同的問題,情況會很好。謝謝。 – Kev