易截截图软件、单文件、免安装、纯绿色、仅160KB

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配置文件读取

Java配置文件读取有各种不同的文件,但是由于打包Jar后的路径改变,往往在项目中能正确读取的配置文件在Jar后变成文件不存在的杯具,下在提出几各不同的配置文件读取方式,仅供参考
一、直接文件读取
File f = new File("you config file path");
FileReader fr = new FileReader(f);
BufferReader br = new ......

java 类编译流程

1.代码的装入
2.代码的校验
3.和代码的执行
体会: dao层 方法名 修改后 调用其的 services 。action 都将被重新 编译。
--- 基本类型使用 :
体会:dao层 基本类型 尽量使用对象类型,以为 基本类型 能自动类型提升 而对象类型 为 null 主动类型转换 会报错:NullPointerException
 小心 类型主动提升 &nb ......

Java中Timer的使用

JAVA技巧(Java定时执行任务的实现方法)2009年02月07日 星期六 10:36定时执行任务的三种方法:     
1)java.util.Timer.     
2)ServletContextListener.     
3)org.springframework.scheduling.timer.ScheduledTimerTask  & ......

smtp of java mail

send mail use smtp .u can send text or html, send to many peoples if u have a email user and pwd and the smtp of the email which u use.
package org.lc.smtp;
import java.io.IOException;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.Message;
import javax.mai ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号