易截截图软件、单文件、免安装、纯绿色、仅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与flex通信

  (转)java与flex通信
一、准备:
服务端:JDK1.5 (这个不用介绍了吧?)
服务端IDE:eclipse (它的主页)
客户端:FLEX 3 (Adobe&reg; Flex&reg; 3 是用于构建和维护在所有主要浏览器、桌面和操作系统一致地部署的极具表现力的 Web 应用程序的高效率的开放源码框架。)
客户端IDE:Flex Builder 3 ......

java读取properties属性文件值方法

在使用hibernate或者spring的时候,我们往往通过配置文件配置数据库连接属性。但这次项目中并没有用到hibernate和spring,只用到了struts2。要如何实现通过读取文件配置获取属性值呢?ResourceBundle这个类可是实现读取properties文件来获取值
在java中:
public final static Object initLock = new Object();
privat ......

JAVA读取外部资源的方法

在java代码中经常有读取外部资源的要求:如配置文件等等,通常会把配置文件放在classpath下或者在web项目中放在web-inf下.
1.从当前的工作目录中读取:
        try {
            BufferedReader in = new BufferedReader(new InputStreamRea ......

[JAVA] 深克隆 另外实现方法【序列化】

private static List cloneObject(
   Object obj) throws Exception {
  ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  ObjectOutputStream out = new ObjectOutputStream(byteOut);
  out.writeObject(obj);
  ByteArrayInputStream byt ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号