|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
专门做了这个例子;而java的这个例子好像就是为了教学而写的,很多教学目的的例子是不考虑优化、性能的。
这是action页面,
packagetester.business.maitain;
importtclcc.tester.util.Selector;
importorg.apache.struts.action.*;
importjavax.servlet.http.*;
importjava.util.*;
importorg.apache.struts.upload.FormFile;
importjava.io.*;
publicclassMaintainAction
extendsAction{
publicActionForwardexecute(ActionMappingactionMapping,
ActionFormactionForm,
HttpServletRequesthttpServletRequest,
HttpServletResponsehttpServletResponse){
/**@todo:completethebusinesslogichere,thisisjustaskeleton.*/
MaintainFormmaintainForm=(MaintainForm)actionForm;
TrainPlanDAOtrainPDAO=newTrainPlanDAO();
TrainplantrainPlan=newTrainplan();
trainPlan=maintainForm.getTrainPlan();
FormFiletheFile=null;
theFile=maintainForm.getTheFile1();
Stringp_accessory;
p_accessory=theFile.getFileName();
try{
InputStreamstream=theFile.getInputStream();//把文件读进
StringfilePath=httpServletRequest.getRealPath("/");//取以后体系路径
ByteArrayOutputStreambaos=newByteArrayOutputStream();
OutputStreambos=newFileOutputStream(filePath+"sub"+"/"+
theFile.getFileName());//创建一个上传文件的输入流
//System.out.println(filePath+"/"+file.getFileName());
intbytesRead=0;
byte[]buffer=newbyte[8192];
while((bytesRead=stream.read(buffer,0,8192))!=-1){
bos.write(buffer,0,bytesRead);//将文件写进服务器
}
bos.close();
stream.close();
}catch(Exceptione){
System.err.print(e);
}
try{
trainPlan.setP_accessory(p_accessory);
trainPDAO.addTrainPlan(trainPlan);//挪用数据库拔出办法
System.out.println("success");
}catch(Exceptionex){
}
httpServletRequest.setAttribute("trainPlain",trainPlan);
return(actionMapping.findForward("trainplanCreated"));
}
}
C#是不行的,比如说美国的航天飞船里就有java开发的程序以上是我的愚见,其实不管那种语言,你学好了,都能找到好的工作, |
|