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 ^^
Related Article: File Upload using jsp
is a JSP discussion thread by josiefrut that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: file, jsp, upload.
gingerfish
Light Poster
47 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.3674 seconds
using 2.7MB