Meaningless Drivel is fun!
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

inputting the excel file to java servlet pgm

Ron Isac

Joined: Dec 22, 2004
Posts: 9
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.

<body bgcolor="green">
<form method="post" action="http://localhost:8080/examples/servlet/Ron1">
<td><input type=file name="path"></td>
<input type=submit value= "submit" >

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 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
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);
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");

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.

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.
I agree. Here's the link:
subject: inputting the excel file to java servlet pgm
It's not a secret anymore!