package servlet;
import java.io.*;
import java.io.File;
import java.sql.*;
import java.util.*;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.*;
import DB.conndb;
public class upload1 extends HttpServlet {
/**
* Constructor of the object.
*/
public upload1() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
response.setCharacterEncoding("gbk");
PrintWriter out=response.getWriter();
SmartUpload su =new SmartUpload();
su.initialize(this.getServletConfig(), request, response);
su.setAllowedFilesList("gif,jpg,png,bmp,jpeg,JPEG,BMP,GIF,JPG,PNG");
String realPath = this.getServletContext().getRealPath("");
String path=realPath+"\\photo\\"+request.getSession().getAttribute("username");
// String fileName=path+su.getFiles().getFile(0).getFileName();
System.out.println(""+realPath);
System.out.println(""+path);
File f=new File(path);
if(!f.exists()){f.mkdirs();}
/* File checkFile = new File(fileName);
if(checkFile.exists()){
out.println("<p>文件已经存在.</p>");
response.sendRedirect("upload.jsp");
}*/
try {
su.upload();
int count=su.save(path);
System.out.println(""+count);
com.jspsmart.upload.File file=su.getFiles().getFile(0);
System.out.println(""+file.getFileName());
Date date=new Date();
String s=""+date.getYear()+date.getMonth()+date.getDay()+date.getHours()+date.getHours()+date.getMinutes()+date.getSeconds()+file.getFileName();
System.out.println(s);
file.saveAs(path+"\\\\"+s);
String username=request.getSession().getAttribute("username").toString();
String note=su.getRequest().getParameter("note");//注意这是接收表单传过来的参数
String authority=su.getRequest().getParameter("Item1");
String album=su.getRequest().getParameter("Item2");
System.out.println(username);
System.out.println(note);
System.out.println(authority);
System.out.println(album);
String sql="insert into photo(user_id,note,path,authority,album_name) values('"+username+"','"+note+"','"+username+"/"+s+"','"+authority+"','"+album+"')";
String sql1="select * from photo where album_name='"+album+"'";
System.out.println(sql1);
String sql2="update album set fengmian='"+"/photo/"+username+"/"+s+"' where album_name='"+album+"'";
System.out.println(sql2);
conndb con =new conndb();
ResultSet rs=null;
rs=con.executeQuery(sql1);
if(!rs.next()){
con.executeUpdate(sql2);
};
con.executeUpdate(sql);
String path1=path+"\\"+file.getFileName();
File f1=new File(path1);
if(f1.isFile()&&f1.exists()){f1.delete();}
out.print("<script language='javascript'>alert('照片上传成功!');window.location.href='myalbum';</script>");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
个人相册系统 (233个子文件)
1ca4dc7580c04d16b0e33b8ab0dd9745da5541c5 257B
blogPhotoAd 24B
upload1.class 5KB
myinfo1.class 4KB
delete.class 4KB
myphoto.class 4KB
friendphoto.class 4KB
friendalbum.class 4KB
mycomment.class 3KB
albumDao.class 3KB
myalbum.class 3KB
addfd.class 3KB
myfriend.class 3KB
mynews.class 3KB
friendcomment.class 3KB
creatalbum.class 3KB
Zhuce.class 3KB
upload.class 3KB
jieshouask.class 3KB
conndb.class 3KB
xiugai.class 3KB
newsDao.class 2KB
commentDao.class 2KB
photoDao.class 2KB
addcomment.class 2KB
LoginDeal.class 2KB
friendDao.class 2KB
myinfo.class 2KB
myinfoDao.class 2KB
SetCharacterEncodingFilter.class 2KB
myinfo1.class 1KB
album.class 1KB
photo.class 1KB
news.class 1KB
comment.class 1KB
friend.class 762B
.classpath 529B
org.eclipse.wst.common.component 455B
org.eclipse.wst.jsdt.ui.superType.container 49B
global_base_780b8ff.css 185KB
styleV1.3.css 112KB
global.css 20KB
square.css 9KB
base.css 7KB
使用说明.doc 4.93MB
软件测试报告.doc 1.06MB
概要设计.doc 1019KB
详细设计.doc 488KB
需求分析.doc 240KB
源代码说明.doc 41KB
解决方案.docx 143KB
WhiteLoading.gif 11KB
none160.gif 11KB
sh.gif 1KB
CustomBlackNext.gif 1KB
CustomBlackPrevious.gif 1KB
sina_icon.gif 1KB
sh_icon.gif 1KB
sj.gif 784B
hx.gif 744B
sina.gif 604B
qq.gif 545B
qq_kj.gif 544B
rr.gif 535B
CustomBlackClose.gif 518B
db.gif 432B
qq_icon.gif 271B
hx_logo.gif 238B
gd_zf.gif 181B
photo1.iml 1KB
mysql-connector-java-5.1.7-bin.jar 693KB
commons-beanutils.jar 184KB
javax.persistence.jar 127KB
commons-io-1.4.jar 106KB
javax.servlet.jsp.jar 77KB
javax.servlet.jar 68KB
commons-fileupload-1.2.1.jar 56KB
javax.ejb.jar 46KB
javax.resource.jar 43KB
javax.servlet.jsp.jstl.jar 27KB
javax.jms.jar 25KB
jspsmartupload.jar 12KB
javax.transaction.jar 9KB
javax.annotation.jar 8KB
upload1.java 4KB
delete.java 4KB
myphoto.java 4KB
myinfo1.java 4KB
friendphoto.java 3KB
friendalbum.java 3KB
mycomment.java 3KB
addfd.java 3KB
albumDao.java 3KB
Zhuce.java 3KB
friendcomment.java 3KB
myalbum.java 3KB
myfriend.java 3KB
mynews.java 3KB
creatalbum.java 3KB
newsDao.java 3KB
共 233 条
- 1
- 2
- 3
资源评论
JoeToffler
- 粉丝: 3
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功