I new to Jsp. So dun quite understand what you mean.
I writing a webpage using jsp. I will allow the user to choose a file in his own directory. Then now i need to obtain the content in the file to store it in the database. I not sure how to do declaration and writing the code for it. Do you have any idea? Please guide me. Thank you.
sorry for my late reply,
although you are new to jsp, you should have basic understanding of java, right?
1.) Write a JSP, which allow user to upload file, like this:
<jsp:useBean id="uploadFileBean" scope="page" class="oreilly.servlet.MultipartRequest" />
<%
String type = request.getContentType();
if (type.toLowerCase().startsWith("multipart/form-data")) {
uploadFileBean.upload(request, "/home/tomcat/tmpSpace/");
%>
<html>
<form action="currentPage" method="post">
<input type="File" id="upfile" name="testFile" >
<input id="upload" name="upload" type="submit" value="Upload">
</form>
</html>
You should obtain the class "MultipartRequest" from oreilly, (if any better class, please let me know), the original one is a servlet class, I made a little modification to change it to javaBean.
Whenever user press the "Upload" button, selected file will be uploaded to server in dir "/home/tomcat/tmpSpace/", (I use Linux Tomcat).
2.) Now you can do anything with the file, since the file had already in server side.
Try make good use of java.io.File
Rex