/** *照片实体类 * */ 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+"https://www.jb51.net/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>" > <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" placeholder="请输入用户名"/> <input type="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+"https://www.jb51.net/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>" > <title>person message</title> </head> <body> <center>相册界面</center> 当前用户:<%=request.getSession().getAttribute("username")%> <br> <a href="https://www.jb51.net/cre.jsp" >去创建相册</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() %>" >添加照片</a></td> <td><a href="show.jsp?phid=<%=pojo.getId() %>" >查看照片</a></td> <td><a href="del.jsp?aid=<%=pojo.getId() %>" >删除相册</a></td> </tr><br> <% } %> </body> </html>
cre.jsp创建相册