ssh上传图片代码(ssh上传图片代码是什么)
admin 发布:2022-12-19 16:39 112
今天给各位分享ssh上传图片代码的知识,其中也会对ssh上传图片代码是什么进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
ssh上传图片的问题
上传图片
提交jsp页面:
s:form action ="sys_fileUpload.action" method ="post" enctype ="multipart/form-data"
s:file name ="myFile" label ="Image File" /
s:textfield name ="caption" label ="Caption" /
s:submit/s:submit
/s:form
action:
private static final long serialVersionUID = 572146812454l ;
private static final int BUFFER_SIZE = 16 * 1024 ; //缓冲器大小
private File myFile;
private String caption;
private String myFileContentType;//上传文件的类型
private String myFileFileName;//上传文件的文件名,该文件名不包括文件的路径
private String imageFileName;
public void setMyFilemyFileContentType(String myFileContentType) {
this .myFileContentType = myFileContentType;
}
public void setMyFileFileName(String fileName) {
this .myFileFileName = fileName;
}
public void setMyFile(File myFile) {
this .myFile = myFile;
}
public String getImageFileName() {
return imageFileName;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this .caption = caption;
}
private static void copy(File src, File dst) {
try {
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(src), BUFFER_SIZE);
out = new BufferedOutputStream( new FileOutputStream(dst), BUFFER_SIZE);
byte [] buffer = new byte [BUFFER_SIZE];
while (in.read(buffer) 0 ) {
out.write(buffer);
}
} finally {
if ( null != in) {
in.close();
}
if ( null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getExtention(String fileName) {
int pos = fileName.lastIndexOf( "." );
return fileName.substring(pos);
}
public String execute() {
imageFileName = new Date().getTime() + getExtention(myFileFileName);
File imageFile = new File(ServletActionContext.getServletContext().getRealPath("/") +imageFileName);
copy(myFile,imageFile);
return "success";
}
struts配置:
package name="p0" extends="struts-default"
action name ="sys_fileUpload" class ="action.FileAction" method="execute"
result name ="success" /success.jsp /result
/action
/package
显示jsp页面:
img src ='s:property value ="imageFileName" / ' /
br /
s:property value ="caption" /
以上代码图片地址没有存入数据库,你可以将获取存入地址写入数据库,然后在页面从数据库读出来。
JAVA,SSH怎么获取图片上传时间
第一种,Java代码获取当前系统时间。
Date date =new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
Sting time = dateFormat.format(date);
第二种,sql语句直接插入当前时间。
instre into table values(now())
第三种,建表时候将时间字段默认是设置成 CURRENT_TIMESTAMP
例如: create table usertable(
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(24) NOT NULL,
`createTime` datetime default CURRENT_TIMESTAMP
)
插入数据的时候,只需要写入 name 即可。id、createtime都自动生成数据。
insert into usertable (name) values("张三");
·
·
如何在SSH中插入图片到数据库中
如果是图片要存在文件夹里面,使用Struts2默认的fileupload插件就好。很简单的,要是图片存在数据库里面的画就得使用二进制了,我没做过Oracle里面支持
,其他数据库就不知道了
ssh上传图片代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于ssh上传图片代码是什么、ssh上传图片代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-17网络营销师是做什么的,网络营销师培训费用是多少
- 05-17seo全称是什么意思,seo全拼
- 05-17做公司网页,做公司网页有什么简单的方法
- 05-17seo信息是什么,seo内容是什么意思
- 05-16设计师经常用的网站,设计师一般用什么网站
- 05-16seo网络推广技术,seo网络推广什么意思
- 05-16外包公司什么意思,外包公司什么意思缺点
- 05-15零基础学什么技术好,零基础学什么技术好开店
- 05-15网络维护是做什么的,网络维护是做什么的好学吗
- 05-14外链网站是什么,外链是啥
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接