package com.wy.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Files;
import com.wy.dao.OperationData;
import com.wy.form.Photo;
import com.wy.form.UserInfo;
public class PhotoServlet extends HttpServlet {
private String info = "";
private OperationData data = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
info = request.getParameter("info");
// 根据页面中info对象的不同值,将执行不同的操作
if (info.equals("userQueryPhoto")) {
this.user_queryPhoto(request, response);
}
if (info.equals("userUploadPhoto")) {
this.user_uploadPhoto(request, response);
}
if (info.equals("queryOnePhoto")) {
this.queryOnePhoto(request, response);
}
if (info.equals("queryPhotoList")) {
this.user_queryPhotoList(request, response);
}
if (info.equals("queryOnePhoto")) {
this.queryOnePhoto(request, response);
}
if (info.equals("queryPhotoSlide")) {
this.queryPhotoSlide(request, response);
}
if (info.equals("userDeletePhoto")) {
this.user_deletePhoto(request, response);
}
if (info.equals("userprintPhoto")) {
this.user_printPhoto(request, response);
}
if (info.equals("forward_index")) {
this.forward_index(request, response);
}
}
// 转向首页操作
public void forward_index(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
List list = new OperationData().queryPhotoList();
request.setAttribute("list", list);
request.getRequestDispatcher("photoIndex.jsp").forward(request,
response);
}
// 设置水印的图片
public void user_printPhoto(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
data = new OperationData();
Integer id = Integer.valueOf(request.getParameter("id"));
String condition = "id = '" + id + "'";
List list = data.photo_queryList(condition);
Photo photo1 = (Photo) list.get(0);
String filePath = request.getRealPath(photo1.getPhotoAddress()); // 设置图片的源文件
String print = "savePrint/" + System.currentTimeMillis() + ".JPG";
String printPath = request.getRealPath(print); // 设置水印图片的位置
/** ******************************************************************************* */
if (!photo1.getPrintAddress().equals("0")) {
String path = request.getRealPath(photo1.getPrintAddress());
java.io.File file1 = new java.io.File(path);
if (file1.exists()) {
file1.delete();
}
}
/** ******************************************************************************* */
String printInforamtion = com.wy.tools.Encrypt.toChinese(request
.getParameter("information"));
String information = "添加水印效果失败!";
if (com.wy.tools.ImageUtils.createMark(filePath, printPath,
printInforamtion)) {
Photo photo2 = new Photo();
photo2.setId(photo1.getId());
photo2.setPrintAddress(print);
if (data.updatePhoto(photo2)) {
information = "添加水印效果成功!";
}
}
request.setAttribute("information", information);
List list1 = data.photo_queryList(condition);
Photo photo3 = (Photo) list1.get(0);
request.setAttribute("photo", photo3);
request.getRequestDispatcher("photoShow.jsp")
.forward(request, response);
}
// 删除图片
public void user_deletePhoto(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
data = new OperationData();
Integer id = Integer.valueOf(request.getParameter("id")); // 从页面中获取要删除相片的id号
String condition = "id=" + id; // 设置以id为条件,设置查询内容
List list = data.photo_queryList(condition); // 根据id值进行查询相片的一组信息
String address = null; // 设置存放服务器端地址对象
String print = null;
String type = null; // 设置相片所在相册对象
if (list.size() == 1) { // 判断查询的集合内容是否就存在一组数据
Photo photo = (Photo) list.get(0);
address = photo.getPhotoAddress(); // 获取数据库中相片存放服务器端的地址
print = photo.getPrintAddress();
type = photo.getPhotoType(); // 获取相片所在相册的类型
}
String path = request.getRealPath("/" + address); // 获取文件的实际地址
data.photo_delete(id); // 删除相片所对应的SQL语句
// 下面的操作是根据文件的所在位置进行删除操作
java.io.File file1 = new java.io.File(path);
if (file1.exists()) {
file1.delete();
}
String printPath = request.getRealPath("/" + print);
java.io.File file2 = new java.io.File(printPath);
if (file2.exists()) {
file2.delete();
}
// 将文件的类型保存在request范围内容
request.setAttribute("type", type);
request.getRequestDispatcher("dealwith.jsp").forward(request, response);
}
// 实现用户上传自己的图片
public void user_uploadPhoto(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
data = new OperationData();
com.jspsmart.upload.SmartUpload su = new com.jspsmart.upload.SmartUpload();
String information = "您输入的数据有误,添加相片失败!";
try {
su.initialize(this.getServletConfig(), request, response); // 设置长传操作的初始化
su.setMaxFileSize(2 * 1024 * 1024); // 设置上传文件的大小
su.upload();
Files files = su.getFiles(); // 获取上传的文件操作
for (int i = 0; i < files.getCount(); i++) {
File singleFile = files.getFile(i); // 获取上传文件的单个文件
String fileType = singleFile.getFileExt(); // 获取上传文件的扩展名
String[] type = { "JPG", "jpg", "gif", "bmp", "BMP" }; // 设置上传文件的扩展名
int place = java.util.Arrays.binarySearch(type, fileType); // 判断上传文件的类型是否正确
String code = su.getRequest().getParameter("code"); // 获取表单中验证码内容
String codeSession = (String) request.getSession()
.getAttribute("rand"); // 获取客户端session中验证码的值
if (code.equals(codeSession)) { // 判断验证码是否正确
if (place != -1) { // 判断文件扩展名是否正确
if (!singleFile.isMissing()) { // 判断该文件是否被选择
String photoName = su.getRequest().getParameter(
"photoName")
+ i; // 获取相片的名称
String photoType = su.getRequest().getParameter(
"photoType"); // 获取相册名称
String photoTime = su.getRequest().getParameter(
"photoTime"); // 获取相册上传时间
String username = su.getRequest().getParameter(
"username"); // 获取上传用户名
String photoSize = String.valueOf(singleFile
.getSize()); // 获取上传文件的大小
String filedir = "savefile/"
+ System.currentTimeMillis() + "."
+ singleFile.getFileExt(); // 以系统时间作为上传文件名称,设置上传文件的完整路径
String smalldir = "saveSmall/"
+ System.currentTimeMillis() + "."
+ singleFile.getFileExt();
Photo photo = new Photo();
/** ********将photo对象中的属性进行一一赋值*** */
photo.setPhotoName(photoName);
photo.setPhotoType(photoType);
photo.setPhotoSize(photoSize);
photo.setPhotoTime(photoTime);
photo.setUsername(username);
photo.setPhotoAddress(filedir);
photo.setSmallPhoto(smalldir);
/** ************************************ */
if (data.photo_save(photo)) { // 实现上传操作的SQL语句
singleFile.saveAs(filedir, File.SAVEAS_VIRTUAL); // 执行上传操作
com.wy.tools.ImageUtils.createSmallPhoto(
request.getRealPath("/" + filedir),
request.getRealPath("/" + smalldir));
information = "您�
没有合适的资源?快使用搜索试试~ 我知道了~
java web网络相册源代码+程序说明书.zip
共158个文件
jpg:99个
jsp:13个
gif:9个
需积分: 0 0 下载量 2 浏览量
2023-03-21
15:55:55
上传
评论
收藏 21.18MB ZIP 举报
温馨提示
系统介绍 讯友网络相册主要实现以下目标:提供用户的操作,如用户注册和登录,相片的浏览,如幻灯片显示,分栏显示以及滚动显示等,以及对照片的操作,如上传,删除等。 操作注意事项 本系统的基本用户名为:mr,密码为:mrsoft
资源推荐
资源详情
资源评论
收起资源包目录
java web网络相册源代码+程序说明书.zip (158个子文件)
1220576675125.bmp 158KB
PhotoServlet.class 10KB
OperationData.class 6KB
UserInfoServlet.class 4KB
ImageUtils.class 3KB
JDBConnection.class 3KB
Photo.class 2KB
Encrypt.class 2KB
UserInfo.class 2KB
.classpath 510B
org.eclipse.wst.jsdt.ui.superType.container 49B
style1.css 4KB
style.css 3KB
Thumbs.db 256KB
Thumbs.db 8KB
Thumbs.db 7KB
Thumbs.db 6KB
程序使用说明.doc 75KB
bg.gif 54KB
9.gif 14KB
bg_1.gif 10KB
11.gif 4KB
10.gif 2KB
register.gif 2KB
land.gif 2KB
21.gif 2KB
22.gif 2KB
sqljdbc.jar 570KB
jsmartcom_zh_CN.jar 13KB
PhotoServlet.java 12KB
OperationData.java 7KB
UserInfoServlet.java 5KB
Photo.java 3KB
JDBConnection.java 3KB
ImageUtils.java 2KB
UserInfo.java 2KB
Encrypt.java 1KB
1220578198218.JPG 1.61MB
1220945562781.JPG 1.5MB
1220527234750.JPG 1.22MB
1220576944343.jpg 892KB
1220524898109.jpg 892KB
1220524459671.jpg 625KB
1220576122453.jpg 436KB
1220524897812.jpg 436KB
1220524898031.jpg 429KB
1220524459546.jpg 429KB
1220525047015.jpg 423KB
1220576355859.jpg 380KB
1220577229984.JPG 347KB
1220525047140.jpg 278KB
1220525046937.jpg 274KB
1220576407718.jpg 272KB
1220851592765.JPG 266KB
1220577284937.JPG 266KB
1220851256265.JPG 262KB
1220576841703.jpg 262KB
1220577285015.JPG 260KB
1220611045015.JPG 254KB
1220611471437.JPG 254KB
1220577489015.JPG 254KB
1220611294375.JPG 254KB
1220611468796.JPG 252KB
1220611044859.JPG 252KB
1220611294156.JPG 252KB
1220577489062.JPG 252KB
1220851673546.JPG 244KB
1220851593406.JPG 242KB
1220851592171.JPG 238KB
1220851673046.JPG 233KB
15.jpg 207KB
1220851594390.JPG 202KB
1220577285046.JPG 200KB
1220576325718.jpg 199KB
1220611045062.JPG 194KB
1220577489171.JPG 194KB
1220611472390.JPG 194KB
1220611294437.JPG 194KB
1220576165359.jpg 180KB
1220525046843.jpg 177KB
1220611469984.JPG 165KB
1220611044718.JPG 165KB
1220611294234.JPG 165KB
1220577489140.JPG 165KB
1220611470718.JPG 165KB
1220611044921.JPG 165KB
1220611294312.JPG 165KB
1220525082281.jpg 164KB
1220576076640.jpg 164KB
9.jpg 152KB
1220524971546.jpg 147KB
1220576613312.jpg 147KB
1.jpg 146KB
12.jpg 145KB
1220851329531.JPG 127KB
1220525082031.jpg 123KB
1220576076703.jpg 123KB
18.jpg 111KB
1220851331203.JPG 108KB
1220851331828.JPG 108KB
共 158 条
- 1
- 2
资源评论
阿星先森
- 粉丝: 150
- 资源: 1453
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功