954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to upload and read file content using JSP?

i have these two separate files:

html form:

<form name="form" action="1.jsp" method="post">

<b>File Upload:</b>
	<input type=file name="seqFile"> 
	<input type=submit name="submit" value="submit" >
	</form>

and JSP file 1.jsp:

<%@ page language="java" import="java.io.*" errorPage="" %>

<%
  
 if(request.getParameter("seqFile")!=null){

//"C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT/test/seq.txt"

			String file = request.getParameter("seqFile");
			FileReader testRead;
			testRead = new FileReader(file);
			int tempChar;
			String tempStr = "";
			String seque = "";
			
			
			try {
			do {
			tempChar = testRead.read();
			if (tempChar == -1) {
			break;
			}
			tempStr = tempStr + (char)tempChar;
			} while(true);
			
		seque = tempStr.toString();
			}
			catch (Exception e) {
			out.println("Error Message : " + e.toString());
		}
		finally {
			
		testRead.close();
			}
			
			out.print(seque);
			out.print(file);
}
else
out.print("no file");	
        %>

i want to upload file and print out or read the content of file but something is wrong with my code, it has something to do with the file, like it cannot find the source file.

can someone please help me
plz plz plz
thanks ^^

gingerfish
Light Poster
47 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: