Reading file using JSP

I got a file name from user. How can i declare a write code to read the content of the file. Please help...
[121 byte] By [caiyun01] at [2007-9-26 1:14:33]
# 1
Do you mean you want to read a file from client machine?If so, user should upload that file to server first, check the MultipartRequest class from O'reilly book, Java Servlet Programming v1.1, or search this forum for "file upload" or "multipartRequest".
rexwkk at 2007-6-29 0:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

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.

caiyun01 at 2007-6-29 0:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

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

rexwkk at 2007-6-29 0:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Rex, Thank you. I will try out your coding. Sorry to trouble you.yun
caiyun01 at 2007-6-29 0:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...