jsp实现仿QQ空间新建多个相册名称并向相册中添加照片功能

工具:Eclipse,Oracle,smartupload.jar;语言:jsp,Java;数据存储:Oracle。

实现功能介绍:

主要是新建相册,可以建多个相册,在相册中添加多张照片,删除照片,删除相册,当相册下有照片时先删除照片才能删除相册。

因为每个相册和照片要有所属人,所以顺带有登录功能。

声明:只是后端实现代码,前台无任何样式,代码测试可行,仅供参考。

代码:

数据库连接帮助类:

public class JDBCHelper {
 public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
 public static final String URL = "jdbc:oracle:thin:@localhost:1521:xxxx";
 public static final String DBNAME = "scott";
 public static final String PASSWORD = "xxxx";
 public static Connection getConn() throws Exception{
 Class.forName(DRIVER);
 Connection conn = DriverManager.getConnection(URL, DBNAME, PASSWORD);
 return conn;
 }
} 

图片上传时,要修改图片名称,防止上传重名图片将上一张覆盖,这里的做法是将图片名改为由用户ID和精确到毫秒的时间组成,修改图片名的帮助类:

public class PhotoName {
 private String ip;
 public PhotoName(String ip) {
 super();
 this.ip = ip;
 }
 public String getIp() {
 return ip;
 }
 public void setIp(String ip) {
 this.ip = ip;
 }
 public String getTime(){
 Date date = new Date();
 DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
 return df.format(date);
 }
 public String getPhotoName(){
 return this.ip + this.getTime();
 }
} 

实现所有这些的接口类:

public interface UpDAO {
 /**
 * 创建相册名称
 *
 */
 public int creAlbum(AlbumPOJO ap);
 /**
 *显示所创建的所有相册名称
 */
 public List<AlbumPOJO> findAllAlbum(int id);
 public List<PhotoPOJO> findAllPhoto(int id);
 /**
 * 上传照片
 */
 public int upPhoto(PhotoPOJO pp);
 /**
 * 删除相册
 * @param id 相册id
 * @return
 */
 public int delAlbum(int id);
 /**
 * 删除照片
 * @param id 照片id
 * @return
 */
 public int delPhoto(int id);
 /**
 * 登录
 * @param username
 * @param password
 * @return
 */
 public UserPOJO login(String username,String password);
} 

接口的具体实现类:

public class UpDAOImpl implements UpDAO {
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#creAlbum(cn.jvsun.POJO.AlbumPOJO)
 * 创建相册名称
 */
 public int creAlbum(AlbumPOJO ap) {
 int albumNum=this.getAlbumNum();
 Connection conn = null;
 PreparedStatement pstate = null;
 try {
  conn=JDBCHelper.getConn();
  conn.setAutoCommit(false);
  String sql="insert into album(id,a_name,user_id)values(?,?,?)";
  pstate = conn.prepareStatement(sql);
  pstate.setInt(1, albumNum);
  pstate.setString(2,ap.getA_name());
  pstate.setInt(3, ap.getUser_id());
  pstate.execute();
  conn.commit();
 } catch (Exception e) {
  e.printStackTrace();
  try {
  conn.rollback();//出问题就撤回,全不提交
  } catch (SQLException e1) {
  e1.printStackTrace();
  }
 }finally{
  try {
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return albumNum;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#upPhoto(java.lang.String, java.lang.String, int)
 * 上传照片
 */
 public int upPhoto(PhotoPOJO pp) {
 int pNum=this.getPhotoNum();
 Connection conn = null;
 PreparedStatement pstate = null;
 try {
  conn=JDBCHelper.getConn();
  conn.setAutoCommit(false);
  String sql="insert into photo(id,p_name,p_url,p_albumid)values(?,?,?,?)";
  pstate = conn.prepareStatement(sql);
  pstate.setInt(1, pNum);
  pstate.setString(2,pp.getP_name());
  pstate.setString(3, pp.getP_url());
  pstate.setInt(4, pp.getP_albumId());
  pstate.execute();
  conn.commit();
 } catch (Exception e) {
  e.printStackTrace();
  try {
  conn.rollback();//出问题就撤回,全不提交
  } catch (SQLException e1) {
  e1.printStackTrace();
  }
 }finally{
  try {
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return pNum;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#delAlbum(int)
 * 删除相册
 */
 public int delAlbum(int id) {
 int result=0;
 Connection conn = null;
 PreparedStatement pstate = null;
 String sql="delete from album where id="+id+"";
 try {
  conn=JDBCHelper.getConn();
  pstate = conn.prepareStatement(sql);
  result=pstate.executeUpdate();
 } catch (SQLException e) {
  e.printStackTrace();
 } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }finally{
  try {
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
 }
 return result;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#delPhoto(int)
 * 删除照片
 */
 public int delPhoto(int id) {
 int result=0;
 Connection conn = null;
 PreparedStatement pstate = null;
 String sql="delete from photo where id="+id+"";
 try {
  conn=JDBCHelper.getConn();
  pstate = conn.prepareStatement(sql);
  result=pstate.executeUpdate();
 } catch (SQLException e) {
  e.printStackTrace();
 } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }finally{
  try {
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
 }
 return result;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#login(java.lang.String, java.lang.String)
 * 用户登录
 */
 public UserPOJO login(String username, String password) {
 UserPOJO user=null;
 Connection conn = null;
 PreparedStatement pstate = null;
 ResultSet res = null;
 try {
  conn=JDBCHelper.getConn();
  String sql="select id,username from userinfo where username=? and password=?";
  pstate = conn.prepareStatement(sql);
  pstate.setString(1, username);
  pstate.setString(2, password);
  res = pstate.executeQuery();
  while(res.next()){
  user=new UserPOJO(res.getInt(1),username,null);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }finally{
  try {
  res.close();
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return user;
 }
 /**
 * 相册序列号
 */
 public int getAlbumNum(){
 int albumNum=-1;
 Connection conn = null;
 PreparedStatement pstate = null;
 ResultSet res = null;
 try {
  conn=JDBCHelper.getConn();
  String sql="select aid.nextval from dual";
  pstate=conn.prepareStatement(sql);
  res=pstate.executeQuery();
  while(res.next()){
  albumNum=res.getInt(1);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }finally{
  try {
  res.close();
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return albumNum;
 }
 /**
 *照片序列号
 */
 public int getPhotoNum(){
 int photoNum=-1;
 Connection conn = null;
 PreparedStatement pstate = null;
 ResultSet res = null;
 try {
  conn=JDBCHelper.getConn();
  String sql="select pid.nextval from dual";
  pstate=conn.prepareStatement(sql);
  res=pstate.executeQuery();
  while(res.next()){
  photoNum=res.getInt(1);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }finally{
  try {
  res.close();
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return photoNum;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#findAll()
 * 显示所创建的相册名
 */
 public List<AlbumPOJO> findAllAlbum(int id) {
 List<AlbumPOJO> list= new ArrayList<AlbumPOJO>();
 Connection conn = null;
 PreparedStatement pstate = null;
 ResultSet res = null;
 try {
  conn=JDBCHelper.getConn();
  String sql="select id,a_name,user_id from album where user_id=?";
  pstate = conn.prepareStatement(sql);
  pstate.setInt(1, id);
  res = pstate.executeQuery();
  while(res.next()){
  AlbumPOJO ap=new AlbumPOJO(res.getInt(1),res.getString(2),res.getInt(3));
  list.add(ap);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }finally{
  try {
  res.close();
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return list;
 }
 /* (non-Javadoc)
 * @see cn.jvsun.DAO.UpDAO#findAllPhoto(int)
 * 显示照片
 */
 public List<PhotoPOJO> findAllPhoto(int aid) {
 List<PhotoPOJO> list= new ArrayList<PhotoPOJO>();
 Connection conn = null;
 PreparedStatement pstate = null;
 ResultSet res = null;
 try {
  conn=JDBCHelper.getConn();
  String sql="select id,p_name,p_url from photo where P_ALBUMID=?";
  pstate = conn.prepareStatement(sql);
  pstate.setInt(1, aid);
  res = pstate.executeQuery();
  while(res.next()){
  PhotoPOJO pojo=new PhotoPOJO(res.getInt(1),res.getString(2),res.getString(3), aid);
  list.add(pojo);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }finally{
  try {
  res.close();
  pstate.close();
  conn.close();
  } catch (SQLException e) {
  e.printStackTrace();
  }
 }
 return list;
 }
} 

用户,相册,照片三个POJO类:

/** * 用户实体类
 *
 */
public class UserPOJO implements Serializable{
 private static final long serialVersionUID = 7554548269035753256L;
 private int id;
 private String username;
 private String password;
 public int getId() {
 return id;
 }
 public void setId(int id) {
 this.id = id;
 }
 public String getUsername() {
 return username;
 }
 public void setUsername(String username) {
 this.username = username;
 }
 public String getPassword() {
 return password;
 }
 public void setPassword(String password) {
 this.password = password;
 }
 public UserPOJO(int id, String username, String password) {
 super();
 this.id = id;
 this.username = username;
 this.password = password;
 }
 public UserPOJO(String username, String password) {
 this.username = username;
 this.password = password;
 }
 public UserPOJO() {
 super();
 // TODO Auto-generated constructor stub
 }
} 
/**
 * 相册实体类
 *
 */
public class AlbumPOJO implements Serializable{
 private int id;
 private String a_name;
 private int user_id;
 public int getId() {
 return id;
 }
 public void setId(int id) {
 this.id = id;
 }
 public String getA_name() {
 return a_name;
 }
 public void setA_name(String a_name) {
 this.a_name = a_name;
 }
 public int getUser_id() {
 return user_id;
 }
 public void setUser_id(int user_id) {
 this.user_id = user_id;
 }
 public AlbumPOJO(int id, String a_name, int user_id) {
 super();
 this.id = id;
 this.a_name = a_name;
 this.user_id = user_id;
 }
 public AlbumPOJO(String a_name, int user_id) {
 this.a_name = a_name;
 this.user_id = user_id;
 }
 public AlbumPOJO() {
 super();
 // TODO Auto-generated constructor stub
 }
} 
/**
 *照片实体类
 *
 */
public class PhotoPOJO implements Serializable{
 private static final long serialVersionUID = 5937149639009957458L;
 private int id;
 private String p_name;
 private String p_url;
 private int p_albumId;
 public int getId() {
 return id;
 }
 public void setId(int id) {
 this.id = id;
 }
 public String getP_name() {
 return p_name;
 }
 public void setP_name(String p_name) {
 this.p_name = p_name;
 }
 public String getP_url() {
 return p_url;
 }
 public void setP_url(String p_url) {
 this.p_url = p_url;
 }
 public int getP_albumId() {
 return p_albumId;
 }
 public void setP_albumId(int p_albumId) {
 this.p_albumId = p_albumId;
 }
 public PhotoPOJO(int id, String p_name, String p_url, int p_albumId) {
 super();
 this.id = id;
 this.p_name = p_name;
 this.p_url = p_url;
 this.p_albumId = p_albumId;
 }
 public PhotoPOJO(String p_name, String p_url, int p_albumId) {
 this.p_name = p_name;
 this.p_url = p_url;
 this.p_albumId = p_albumId;
 }
 public PhotoPOJO() {
 super();
 // TODO Auto-generated constructor stub
 }
} 

login.jsp实现登录

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>login</title>
 </head>
 <body>
 <%
 request.setCharacterEncoding("utf-8");
 String action=request.getParameter("action");
 UpDAO ud=new UpDAOImpl();
 String username=request.getParameter("username");
 String password=request.getParameter("password");
 UserPOJO pojo=ud.login(username, password);
 if("log".equals(action)){
 if(pojo==null){
  %>
  <h1>登录失败</h1>
  <%
 }else{
  request.getSession().setAttribute("username", username);
  request.getSession().setAttribute("userid", pojo.getId());
  response.sendRedirect("index.jsp");
 }
 }
 %>
 <form action="login.jsp?action=log" method="post">
 <input type="text" name="username" placeholder="请输入用户名"/>
 <input type="password" name="password" placeholder="请输入密码"/>
 <input type="submit"/>
 </form>
 </body>
</html> 

index.jsp实现显示相册

代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>person message</title>
 </head>
 <body>
 <center>相册界面</center>
 当前用户:<%=request.getSession().getAttribute("username")%> <br>
 <a href="cre.jsp" rel="external nofollow" >去创建相册</a><br>
 我的所有相册:<br>
 <%
 int userid=(Integer)request.getSession().getAttribute("userid");
 UpDAO dao=new UpDAOImpl();
 List<AlbumPOJO> list=dao.findAllAlbum(userid);
 for(AlbumPOJO pojo:list){
 %>
 <tr>
 <a>相册id:</a><td><%=pojo.getId() %></td>
 <a>相册名称:</a><td><%=pojo.getA_name() %></td>
 <a>创建者id:</a><td><%=pojo.getUser_id() %></td>
 <td><a href="up.jsp?aid=<%=pojo.getId() %>" rel="external nofollow" >添加照片</a></td>
 <td><a href="show.jsp?phid=<%=pojo.getId() %>" rel="external nofollow" >查看照片</a></td>
 <td><a href="del.jsp?aid=<%=pojo.getId() %>" rel="external nofollow" >删除相册</a></td>
 </tr><br>
 <%
 }
 %>
 </body>
</html> 

cre.jsp创建相册

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>up photo</title>
 </head>
 <body>
 <%
 request.setCharacterEncoding("utf-8");
 String action=request.getParameter("action");
 UpDAO ud=new UpDAOImpl();
 String toCre=request.getParameter("cre");
 int userId=(Integer)request.getSession().getAttribute("userid");
 if("cre".equals(action)){
 AlbumPOJO ap=new AlbumPOJO(toCre,userId);
 int aNum=ud.creAlbum(ap);
 if(aNum!=-1){
  response.sendRedirect("index.jsp");
 }else{
  %>
  <h1>创建相册失败</h1>
  <%
 }
 }
 %>
 <form action="cre.jsp?action=cre" method="post">
 <input type="text" name="cre" placeholder="请输入您要创建的相册名称"/>
 <input type="submit" value="确定">
 </form>
 </body>
</html> 

up.jsp上传照片

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%@ page import="cn.jvsun.tools.*" %>
<%@page import="org.lxh.smart.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>上传照片</title>
 </head>
 <body>
 <%
 int aid=Integer.parseInt(request.getParameter("aid"));
 %>
 <form action="upCheck.jsp" method="post" enctype="multipart/form-data">
 <input type="hidden" name="aid" value="<%=aid %>"/>
 <input type="file" name="photo"/>
 <input type="submit" value="确认上传"/>
 </form>
 </body>
</html> 

upCheck.jsp上传照片的处理页

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%@ page import="cn.jvsun.tools.*" %>
<%@page import="org.lxh.smart.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title></title>
 </head>
 <body>
 <%
 String ip = request.getRemoteAddr();
 ip = ip.replaceAll(":","");
 PhotoName pn=new PhotoName(ip);
 String pName = pn.getPhotoName();//照片名字,是由IP加当前时间组成
 SmartUpload smartupload = new SmartUpload();//实例化上传操作的对象
 //初始化上传文件
 smartupload.initialize(pageContext);
 //准备上传
 smartupload.upload();
 int albumId=Integer.parseInt(smartupload.getRequest().getParameter("aid"));
 //取得文件的后缀
 String endName = smartupload.getFiles().getFile(0).getFileExt();
 //文件保存的路径
 /*String p_url = getServletContext().getRealPath("/")+
   "file/"+pName+"."+endName;*/
 String p_url="K:/workspace/Xiangce/WebRoot/file/"+pName+"."+endName;
 //保存文件
 smartupload.getFiles().getFile(0).saveAs(p_url);
 UpDAO ad=new UpDAOImpl();
 PhotoPOJO pojo=new PhotoPOJO(pName+"."+endName,p_url,albumId);
 int photoNum=ad.upPhoto(pojo);
 if(photoNum != -1){
  request.getSession().setAttribute("phid", albumId);
  response.sendRedirect("show.jsp");
  } else {
 %>
 上传失败
 <%
  }
 %>
 </body>
</html> 

show.jsp显示照片及信息页:

代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>My JSP 'show.jsp' starting page</title>
 </head>
 <body>
 <center>相册界面</center>
 当前用户:<%=request.getSession().getAttribute("username")%> <br>
 <%
 int phid=(Integer)request.getSession().getAttribute("phid");
 UpDAO dao=new UpDAOImpl();
 List<PhotoPOJO> list=dao.findAllPhoto(phid);
 for(PhotoPOJO pojo:list){
 %>
 <tr>
 <a>照片id:</a><td><%=pojo.getId() %></td><br>
 <a>照片名称:</a><td><%=pojo.getP_name() %></td><br>
 <a>照片路径:</a><td><%=pojo.getP_url() %></td><br>
 <a>照片所属相册名称:</a><td><%=pojo.getP_albumId() %></td><br>
 <td><img src="<%=path%>/file/<%=pojo.getP_name() %>" width="100" height="100"/></td>
 <a href="photo_del.jsp?pid=<%=pojo.getId() %>" rel="external nofollow" >删除照片:</a></td><br>
 </tr><br>
 <%} %>
 </body>
</html> 

photo_del.jsp删除照片

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>del</title>
 </head>
 <body>
 <%
 int pid=Integer.parseInt(request.getParameter("pid"));
 int result=0;
 UpDAO dao=new UpDAOImpl();
 result=dao.delPhoto(pid);
 if(result==1){
 out.println("<script>alert('删除成功');window.location.href('show.jsp');</script>");
 }else{
 out.println("<script>alert('出错了');window.location.href('show.jsp');</script>");
 }
 %>
 </body>
</html> 

del.jsp删除相册

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.jvsun.DAO.Impl.*" %>
<%@ page import="cn.jvsun.POJO.*" %>
<%@ page import="cn.jvsun.DAO.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 <title>del</title>
 </head>
 <body>
 <%
 int aid=Integer.parseInt(request.getParameter("aid"));
 int result=0;
 UpDAO dao=new UpDAOImpl();
 result=dao.delAlbum(aid);
 if(result==1){
 out.println("<script>alert('删除成功');window.location.href('index.jsp');</script>");
 }else{
 out.println("<script>alert('删除失败,请先把相册中的照片删掉');window.location.href('index.jsp');</script>");
 }
 %>
 </body>
</html> 

数据库的建表语句:

-- Create table
create table USERINFO
(
 ID NUMBER,
 USERNAME VARCHAR2(30),
 PASSWORD VARCHAR2(30)
)
tablespace USERS
 pctfree 10
 initrans 1
 maxtrans 255
 storage
 (
 initial 64
 minextents 1
 maxextents unlimited
 );
-- Create/Recreate primary, unique and foreign key constraints
alter table USERINFO
 add constraint PID primary key (ID)
 disable;
--上传者
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Create table
create table ALBUM
(
 ID NUMBER not null,
 A_NAME VARCHAR2(30),
 USER_ID NUMBER
)
tablespace USERS
 pctfree 10
 initrans 1
 maxtrans 255
 storage
 (
 initial 64
 minextents 1
 maxextents unlimited
 );
-- Create/Recreate primary, unique and foreign key constraints
alter table ALBUM
 add constraint AL_PID primary key (ID)
 using index
 tablespace USERS
 pctfree 10
 initrans 2
 maxtrans 255
 storage
 (
 initial 64K
 minextents 1
 maxextents unlimited
 );
alter table ALBUM
 add constraint USERID foreign key (USER_ID)
 references USERINFO (ID)
 disable;
--相册表
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Create table
create table PHOTO
(
 ID NUMBER,
 P_NAME VARCHAR2(30),
 P_URL VARCHAR2(50),
 P_ALBUMID NUMBER(30)
)
tablespace USERS
 pctfree 10
 initrans 1
 maxtrans 255
 storage
 (
 initial 64
 minextents 1
 maxextents unlimited
 );
-- Create/Recreate primary, unique and foreign key constraints
alter table PHOTO
 add constraint ALB_ID foreign key (P_ALBUMID)
 references ALBUM (ID);
--相片表 

好了,所有代码就写完了,切记,需要smartupload.jar包,没有的童鞋可以去下载:

smartuploadjar包

以上所述是小编给大家介绍的jsp实现仿QQ空间新建多个相册名称并向相册中添加照片功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • jsp实现仿QQ空间新建多个相册名称并向相册中添加照片功能

    工具:Eclipse,Oracle,smartupload.jar:语言:jsp,Java:数据存储:Oracle. 实现功能介绍: 主要是新建相册,可以建多个相册,在相册中添加多张照片,删除照片,删除相册,当相册下有照片时先删除照片才能删除相册. 因为每个相册和照片要有所属人,所以顺带有登录功能. 声明:只是后端实现代码,前台无任何样式,代码测试可行,仅供参考. 代码: 数据库连接帮助类: public class JDBCHelper { public static final String

  • Android ScrollView滑动实现仿QQ空间标题栏渐变

    今天来研究的是ScrollView-滚动视图,滚动视图又分横向滚动视图(HorizontalScrollView)和纵向滚动视图(ScrollView),今天主要研究纵向的.相信大家在开发中经常用到,ScrollView的功能已经很强大了,但是仍然满足不了我们脑洞大开的UI设计师们,所以我们要自定义-本篇文章主要讲监听ScrollView的滑动实现仿QQ空间标题栏渐变,先看一下效果图: 好了我们切入主题. 有可能你不知道的那些ScrollView属性  •android:scrollbars 设

  • jQuery实现仿QQ空间装扮预览图片的鼠标提示效果代码

    本文实例讲述了jQuery实现仿QQ空间装扮预览图片的鼠标提示效果代码.分享给大家供大家参考,具体如下: 这是一款仿腾讯网QQ空间装扮预览图片的鼠标提示效果,感应鼠标显示图片的介绍信息,当你把鼠标移到图片上的时候,图片的背景会有所变化,并会显示该图片的对应文字内容,是QQ空间使用过的效果. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/jquery-f-qq-zone-pic-view-codes/ 具体代码如下: <!DOCTYPE html

  • PHP仿qq空间或朋友圈发布动态、评论动态、回复评论、删除动态或评论的功能(上)

    我们大部分人都发过动态,想必都知道发动态.回复评论.删除动态的整个过程,那么作为初学者,要模仿这些功能有点复杂的,最起码表的关系得弄清楚~~ 先把思路理一下: (1)用户登录,用session读取当前用户----目的是:该用户可以发表动态,重点是显示该用户好友及他自己发表的动态,并且按发表时间排序. (2)做个发表动态框实现发表动态功能 (3)显示该用户和他好友已经发表对的动态信息,并按发表时间由近到远显示 (4)再每条动态后面做一个评论按钮和删除按钮:实现对动态的评论,回复和删除(斜体部分下一

  • Android仿QQ空间底部菜单示例代码

    之前曾经在网上看到Android仿QQ空间底部菜单的Demo,发现这个Demo有很多Bug,布局用了很多神秘数字.于是研究了一下QQ空间底部菜单的实现,自己写了一个,供大家参考.效果如下图所示:   1.实现原理很简单,底部菜单是一个水平分布的LinearLayout,里面又是五个LinearLayout,它们的layout_weight都为1,意味着底部菜单的子控件将屏幕宽度平均分为5部分.五个LinearLayout除了中间那个,其余都在里面放置ImageView和TextView(中间先空

  • Android开发仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: 这个要实现这个效果可以分几步进行 1.第一步自定义PopupWindow,实现如图的样式,这个继承PopupWindow自定义布局很容易实现 2.得到点击按钮的位置,根据位置是否在屏幕的中间的上方还是下方,将PopupWindow显示在控件的上方或者下方 3.适配问题,因为PopupWindow上面的操作列表

  • Android仿QQ空间动态界面分享功能

    先看看效果: 用极少的代码实现了 动态详情 及 二级评论 的 数据获取与处理 和 UI显示与交互,并且高解耦.高复用.高灵活. 动态列表界面MomentListFragment支持 下拉刷新与上拉加载 和 模糊搜索,反复快速滑动仍然非常流畅. 缓存机制使得数据可在启动界面后瞬间加载完成. 动态详情界面MomentActivity支持 (取消)点赞.(删除)评论.点击姓名跳到个人详情 等. 只有1张图片时图片放大显示,超过1张则按九宫格显示. 用到的CommentContainerView和Mom

  • JS实现的仿QQ空间图片弹出效果代码

    本文实例讲述了JS实现的仿QQ空间图片弹出效果代码.分享给大家供大家参考,具体如下: <script type="text/javascript"> function imageShow(which_click) { var image_path = which_click; //alert(image_path); var tag_top = Math.max(document.documentElement.scrollTop, document.body.scroll

  • 基于jQuery实现仿QQ空间送礼物功能代码

    我们在QQ空间里面有一个送礼物的功能,显示了最近过生日的人.我们只要把鼠标放到如下图的生日快乐那标签上,就会显示可以给该人送的礼物!! 如下图所示: 单击其中的一个礼物,就会马上送出去.但是我们现在是要说的还有单击更多的时候,会另外弹出一个新的窗口在当前页面最前面!如下图显示: 怎么实现那上面的功能呢? 就是把鼠标放上去,弹出一天tips,单击tips里面的控件,之后弹出另外一个弹出框. 网上就会有很多比较好的插件,就先到网上去找了相对应的jquery插件. jquery中tips的有很多插件,

  • Android仿QQ空间顶部条背景变化效果

    本文给大家分享仿QQ空间页面顶部条随界面滑动背景透明度变化的效果,这个效果在其他应用程序中也很常见,技能+1. 一.上代码,具体实现 笔者之前的文章第二部分总是二话不说,直接上代码,很干脆,其实更好的方式是引导读者思考:这个效果如何实现.前期做好效果的功能分析,才能读者更好的理解. QQ空间的这个页面其实并不复杂,我们看看QQ空间的演示界面: 可以看见,整个页面其实只有两个根元素,一个是ListView,一个是标题栏,前者可以上下滑动,给用户呈现内容:后者固定位置不动,类似于一个导航栏,左边一个

随机推荐