We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,134 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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 ^^

1
Contributor
0
Replies
1
View
gingerfish
Light Poster
47 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0572 seconds using 2.71MB