前台页面信息:
<form action="/upload/save" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload" id="file_upload"/>
请输入图片提示信息:<input type="text" name="content" id="content" />
选择输入图片超链地址:<input type="text" name="href" id="href" />
<input type="submit" name="uploadbutton" value="上传"/>
</form>
后台处理信息:
//获取图片路径和备注信息并保证到数据库
public void save(){
// 获取上传的文件
UploadFile uf = getFile("Filedata", "uploads");
// 拼接文件上传的完整路径
String fileName = "http://" + this.getRequest().getRemoteHost() + ":"
+ this.getRequest().getLocalPort() + "/upload/uploads/"
+ uf.getFileName();
this.setAttr("fileName", fileName);
//测试,后台打印文件路径
System.out.println("================fileName:"+fileName);
//创建对象
Picture picture = this.getModel(Picture.class);
//获取表单其余信息
String content1 = getPara("content");
String href1 = getPara("href");
//获取系统时间,用oracle时要特别注意时间类型
Timestamp date1 = new Timestamp(new Date().getTime());
//写入数据库(State的值默认数值为1,既默认为显示状态)
try{
picture.set("Id", "seq_pid.nextval");
picture.set("Address",fileName);
picture.set("State", 1);
picture.set("Content",content1);
picture.set("Href", href1);
picture.set("Stime", date1);
picture.save();
}catch(Exception e){
e.printStackTrace();
}
//打印测试
System.out.println(content1);
System.out.println(href1);
System.out.println(date1);
forwardAction("/index");
}
================fileName:http://0:0:0:0:0:0:0:1:80/upload/uploads/102.jpg
null
null
2016-07-28 11:11:17.592
JFinal action report -------- 2016-07-28 11:11:17 ------------------------------
Controller : com.zerosky.common.controller.UploadController.(UploadController.java:1)
Method : save
Parameter : Upload=Submit Query Filename=10.jpg
--------------------------------------------------------------------------------
JFinal action report -------- 2016-07-28 11:11:17 ------------------------------
Controller : com.zerosky.common.controller.NoticeController.(NoticeController.java:1)
Method : index
UrlPara : index