File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes inputting the excel file to java servlet pgm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "inputting the excel file to java servlet pgm" Watch "inputting the excel file to java servlet pgm" New topic
Author

inputting the excel file to java servlet pgm

Ron Isac
Greenhorn

Joined: Dec 22, 2004
Posts: 9
Hi,
I have created an html file to create a form that will ask the path of the file to be loaded into the servlet program.Please give me a solution,thanks in advance.


<html>
<body bgcolor="green">
<center>
<form method="post" action="http://localhost:8080/examples/servlet/Ron1">
<table>
<tr>
<td><B>ENTER THE PATH OF THE FILE</td>
<td><input type=file name="path"></td>
</tr>
</table>
<input type=submit value= "submit" >
</form>
</body>
</html>

The servlet program that receives the file is shown below. It just only take the name of the file and prints if that is ok.

import java.io.*;
import javax.servlet.*;
import java.lang.*;
import javax.servlet.http.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import com.oreilly.servlet.MultipartRequest;
import org.apache.poi.hssf.usermodel.*;
public class Ron1 extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String u = request.getParameter("FileToUpload");
out.println("The Path is "+u);
System.out.println("The path is "+u);
MultipartRequest multi = new MultipartRequest(request,u,10 * 1024 * 1024);
System.out.println("path is "+u);
Enumeration files = multi.getFileNames();
File fUploadedFile = null;
String sFileName = "";
out.println("path is "+u);
while(files.hasMoreElements())
{
String name = (String)files.nextElement();
out.println("file is "+name);
sFileName = multi.getFilesystemName(name);
String type = multi.getContentType(name);
fUploadedFile = multi.getFile(name);

}
FileInputStream fis= new FileInputStream(fUploadedFile);

HSSFWorkbook wb=new HSSFWorkbook(fis);
System.out.println("The path is "+u);
out.println("File has identified successfully\n");
out.close();
}
}


I am using HSSF to read values from the excel file. I just want to create an instance of a workbook with that excel file object. But error is occurring with MultipartRequest system call.

Regards,
Ron Isac
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
You'd probably be better off posting on an Apache/Jakarta mailing list.
 
jQuery in Action, 2nd edition
 
subject: inputting the excel file to java servlet pgm