java中上传图片
1. ActionForm中添加属性,FormFile类型对象。
private FormFile upLoadFile;
public FormFile getUpLoadFile() {
return upLoadFile;
}
public void setUpLoadFile(FormFile upLoadFile) {
this.upLoadFile = upLoadFile;
}
2. Action 中增加修改方法。
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PayDirMenuForm myForm = (PayDirMenuForm) form;
PayDirMenu myObj = new PayDirMenu();
BeanUtils.copyProperties(myObj, myForm);
PayDirMenuManager mgr = (PayDirMenuManager)
getBean("PayDirMenuManager");
// 获得文件
FormFile file = myForm.getUpLoadFile();//form中增加的属性
// 获得Tomcate的路径
String objpath = request.getRealPath("plan");
// 获得上传的文件的名字
String fileName = file.getFileName();//获取上传图片的文件名
// 截取字符串,获得后缀名
StringsuffixFileName =
fileName.substring(fileName.lastIndexOf("."));
//判断上传文件的类型
if(!".txt".equals(suffixFileName)&&!".doc".equals(suffixFileName)&&!".xls".equals(suffixFileName)&&!".jpg".equals(suffixFileName)&&!".gif".equals(suffixFileName)&&!".ppt".equals(suffixFileName))
{
request.getSession().setAttribute("msg1", "<font
color='red'>上传的文件格式不正确!</font>");
return null;
}
// 获得内容
byte[] fileData = file.getFileData();
if (myObj.getMenuOid() != null && myObj.getMenuOid().intValue() ==
0){ //增加
//写入到流中
FileOutputStream out = new FileOutputStream(new File(objpath + "\\"
+ fileName));
String filePath = objpath + "\\"+ fileName;
out.write(fileData);
out.close();
out.flush();
//写入数据库
myObj.setMenuImage(filePath);
mgr.saveObj(myObj);
}
else
相关文档:
(转)java与flex通信
一、准备:
服务端:JDK1.5 (这个不用介绍了吧?)
服务端IDE:eclipse (它的主页)
客户端:FLEX 3 (Adobe® Flex® 3 是用于构建和维护在所有主要浏览器、桌面和操作系统一致地部署的极具表现力的 Web 应用程序的高效率的开放源码框架。)
客户端IDE:Flex Builder 3 ......
在java代码中经常有读取外部资源的要求:如配置文件等等,通常会把配置文件放在classpath下或者在web项目中放在web-inf下.
1.从当前的工作目录中读取:
try {
BufferedReader in = new BufferedReader(new InputStreamRea ......
try {
Runtime.getRuntime().exec("C:\\xxx.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} ......
学.NET就好比和爹妈一起出门,啥事都不用愁,因为爹妈都给你操心着了。
学Java就像自己出门,你要睁大眼睛看清周围的世界,并决定你自己的方向;
必要的时候,你要脱离一切束缚,自己搞一套框架来适应特殊需求。
在Java的世界里,有着形形色色的开源产品和框架。
它们就好像你在异 ......