This is the action page,
Package Tester.business.maitain
Import tclcc.tester.util.Selector;
Import org.apache.struts.action.*;
Import javax.servlet.http.*;
Import java.util.*;
Import Org.apache.struts.upload.FormFile;
Import java.io.*;
public class Maintainaction
extends Action {
Public actionforward execute (actionmapping actionmapping,
A Ctionform actionform,
HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse) {
/ * * @todo: Complete the business logic here, this is just a skeleton.*/
maintainform maintainform = (maintainform) actio Nform;
Trainplandao Trainpdao = new Trainplandao ();
Trainplan Trainplan = new Trainplan ();
Trainplan = Maintainform.gettrainplan ();
Formfile thefile = null;
Thefile = Maintainform.getthefile1 ();
String p_accessory;
P_accessory = Thefile.getfilename ();
try {
InputStream stream = Thefile.getinputstream ();//Read the file into the
String FilePath = Httpservletrequest.getreaLpath ("/"); Takes the current system path
Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();
OutputStream BOS = new FileOutputStream (FilePath + "\\sub" + "/" +
Thefile.getfilename ());//create an output stream for an uploaded file
//system . OUT.PRINTLN (filepath+ "/" +file.getfilename ());
int bytesread = 0;
byte[] buffer = new byte[8192];
while (bytesread = stream.read (buffer, 0, 8192))!=-1) {
Bos.write (buffer, 0, bytesread);//write file to server
}
Bos.close ();
Stream.Close ();
} catch (Exception e) {
System.err.print (e);
}
try {
Trainplan.setp_accessory (p_accessory);
Trainpdao.addtrainplan (Trainplan);//Call database Insert method
SYSTEM.OUT.PRINTLN ("Success");
} catch (Exception ex) {
}
Httpservletrequest.setattribute ("Trainplain", Trainplan);
Return ( Actionmapping.findforward ("trainplancreated"));
}
}