Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inputting the excel file to java servlet pgm

 
Ron Isac
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic