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
相关文档:
Mysql在默认情况下建立表的字符编码是latin1,所以在插入中文时会出错。
eg:
1、查看表建立的sql源码:
1: sql命令:show create table users
2:
3: 结果:
4: CREATE TABLE `users` (
5: `userID` int(10) unsigned NOT NULL AUTO_INCREMENT,
6: `userName` varchar(4 ......
Java配置文件读取有各种不同的文件,但是由于打包Jar后的路径改变,往往在项目中能正确读取的配置文件在Jar后变成文件不存在的杯具,下在提出几各不同的配置文件读取方式,仅供参考
一、直接文件读取
File f = new File("you config file path");
FileReader fr = new FileReader(f);
BufferReader br = new ......
(转)java与flex通信
一、准备:
服务端:JDK1.5 (这个不用介绍了吧?)
服务端IDE:eclipse (它的主页)
客户端:FLEX 3 (Adobe® Flex® 3 是用于构建和维护在所有主要浏览器、桌面和操作系统一致地部署的极具表现力的 Web 应用程序的高效率的开放源码框架。)
客户端IDE:Flex Builder 3 ......
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 ......
try {
Runtime.getRuntime().exec("C:\\xxx.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} ......