Introduction
I've created a JSP for
browsing to the file to upload. And I've written some controllercode for
creating the form and retrieving the file, it then reads the file and
wites it line by line to the console window. Hopefully this code helps a
bit.
Here is My JSP
Code
<%@ taglib
uri="/WEB-INF/tld/expresso.tld" prefix="expresso" %> <%@ taglib
uri="/WEB-INF/tld/expresso-html.tld" prefix="html" %> <%@ taglib
uri="/WEB-INF/tld/expresso-bean.tld" prefix="bean" %> <%@ taglib
uri="/WEB-INF/tld/expresso-logic.tld" prefix="logic"
%>
<html>
<head> </head>
<body
text="#ffff00" bgcolor="#000000">
<expresso:ErrorTag
/> <p>
<center> <html:form
action="/ExcelUploadController.do" method="POST"
enctype="multipart/form-data"> <table> <tr> <td
align="right"><expresso:LabelTag name="File"
type="input"/></td> <td
align="left"><expresso:InputTag
name="File"/></td> </tr> <tr> <td
align="center" colspan="2"><expresso:TransitionTag name="result"
value="Upload"/></td> </tr> </table> </html:form> </center>
</p> </body> </html>
And this is
the Code for My Controllerimport
com.jcorporate.expresso.core.controller.*; import
com.jcorporate.expresso.core.controller.session.*; import
com.jcorporate.expresso.core.dbobj.DBObject; import
com.jcorporate.expresso.core.dbobj.MultiDBObject; import
com.jcorporate.expresso.core.dbobj.SecuredDBObject; import
com.jcorporate.expresso.core.dbobj.Schema; import
com.jcorporate.expresso.core.db.DBException; import
com.jcorporate.expresso.core.db.DBConnection; import
com.jcorporate.expresso.core.db.DBConnectionPool; import
com.jcorporate.expresso.core.dbobj.ValidValue; import
com.jcorporate.expresso.services.dbobj.SchemaList;
import
java.util.ArrayList; import java.util.Vector; import
java.util.Enumeration; import java.io.*; //for file I/O
public
class ExcelUploadController extends
DBController {
private String
thisClass=ExcelUploadController.class.getName()+".";
public ExcelUploadController()
{ super();
addState(new
State("prompt", "Prompt for Uploading Excel
file")); addState(new
State("result", "Result of
Uploading"));
setInitialState("prompt");
}
public String getTitle()
{ return
("Excel Upload Controller");
}
protected ControllerResponse
runPromptState(ControllerRequest myRequest, ControllerResponse myResponse
) throws
ControllerException
{ //Create
the box for uploading the
file Input
filePrompt = new
Input("File"); filePrompt.setLabel("File
to import
:"); filePrompt.setAttribute("file",
""); filePrompt.setType("file");
myResponse.add(filePrompt);
Transition
uploadButton = new Transition("result",
this); myResponse.add(uploadButton);
return
myResponse;
}
protected
ControllerResponse runResultState(ControllerRequest myRequest,
ControllerResponse myResponse )
throws
ControllerException
{ if
(myRequest.isFileParameter("File")) { try { File
file = new
File(myRequest.getFileName("File")); BufferedReader
br = new BufferedReader(new
FileReader(file)); String
line =
null; while
((line = br.readLine()) !=
null) { System.out.println(line); } br.close(); } catch(Exception
e) { System.out.println(e.getMessage()); } } return
myResponse;
} }
Comments/corrections/?
Please write the author Jan Moons
at Jan.Moons@alcatel.be. |