Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inputting the excel file to java servlet pgm  RSS feed

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd probably be better off posting on an Apache/Jakarta mailing list.
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
ScroogeXHTML 7.2 - RTF to HTML5 / XHTML converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!