我遇到问题“<file_name>.pdf not found as file or resource
”代码从选择的路径上传文件到数据库。以下是我使用的代码:
它读取PDF文件并作为CLOB上传到DB。然而,它应该是一项简单的任务,由于某些原因它无法正常工作。
public class FileUpload extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FileUpload() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String uploadData="";
BusinessLogic bl=new BusinessLogic();
String user=(String) request.getSession().getAttribute("UserName");
//InputStream inputStream = null;
String fileName = request.getParameter("file");
File file = new File(fileName);
try {
// Load an existing document
PdfReader reader = new PdfReader(fileName);
int n = reader.getNumberOfPages();
/*for (int i=1;i<=n;i++)
{*/
/*String str=PdfTextExtractor.getTextFromPage(reader, i);*/
String str=PdfTextExtractor.getTextFromPage(reader, 2);
uploadData=uploadData+str;
/*}*/
bl.updateAckFile(file,uploadData,user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
bl.updateAckFile(file,fis,user);*/
RequestDispatcher rd = request.getRequestDispatcher("/AcknowFile.jsp");
rd.forward(request, response);
}
}
非常感谢您提供任何帮助。