一、新闻页实现

首先在services包下—》Impl—》NewsServicesImpl实现类
|
|
NewsServices接口
其次:WebContent文件下—-》news—->文件—-》newsDetailList.jsp
剩余jsp文件
addNewsDetail;addNewsDetailSubmit;deleteNewsDetail;upDatenNewsDetail;upDateNewsDetailSubmit;error

NewsServicesImpl:

  1. //接口实现类---Services层存在是因为之后要形成一对多的DAO
  2. public class NewsServicesImpl implements NewsServices{
  3. NewsDetailDao ndd=new NewsDetailDaoImpl();
  4. public List<NewsDetail> getNewsDetailList(){
  5. return ndd.getNewsDetailList();
  6. }
  7. public int insert(NewsDetail nd){
  8. return ndd.insert(nd);
  9. }
  10. public int update(NewsDetail nd){
  11. return ndd.update(nd);
  12. }
  13. public NewsDetail getNewsDetailById(Integer id){
  14. return ndd.getNewsDetailById(id);
  15. }
  16. public int delete(Integer id){
  17. return ndd.delete(id);
  18. }
  19. }

NewsServices:

  1. //新闻详情业务接口
  2. public interface NewsServices {
  3. public List<NewsDetail> getNewsDetailList();
  4. public int insert(NewsDetail nd);
  5. public NewsDetail getNewsDetailById(Integer id);
  6. public int delete(Integer id);
  7. public int update(NewsDetail nd);
  8. }

addNewsDetail:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <form action="addNewsDetailSubmit.jsp" method="post">
  11. 新闻类别:
  12. <select name="categoryId">
  13. <option value="1">国内</option>
  14. <option value="2">国际</option>
  15. <option value="3">娱乐</option>
  16. <option value="4">军事</option>
  17. <option value="5">财经</option>
  18. <option value="6">天气</option>
  19. </select><br/>
  20. 新闻标题:
  21. <input type="text" name="title"><br/>
  22. 新闻摘要:
  23. <input type="text" name="summary"><br/>
  24. 新闻内容:
  25. <textarea rows="20" cols="40" name="content"></textarea><br/>
  26. <input type="submit" value="提交">
  27. </form>
  28. </body>
  29. </html>

addNewsDetailSubmit:

  1. <%@page import="java.util.Date"%>
  2. <%@page import="cn.bdqn.services.impl.NewsServicesImpl"%>
  3. <%@page import="cn.bdqn.pojo.NewsDetail"%>
  4. <%@page import="cn.bdqn.services.NewsServices"%>
  5. <%@ page language="java" contentType="text/html; charset=UTF-8"
  6. pageEncoding="UTF-8"%>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <title>Insert title here</title>
  12. </head>
  13. <body>
  14. <%
  15. request.setCharacterEncoding("UTF-8");
  16. response.setCharacterEncoding("UTF-8");
  17. String categoryId=request.getParameter("categoryId");
  18. String title=request.getParameter("title");
  19. String summary=request.getParameter("summary");
  20. String content=request.getParameter("content");
  21. NewsServices ns=new NewsServicesImpl();
  22. NewsDetail nd=new NewsDetail();
  23. nd.setCategoryId(Integer.parseInt(categoryId));
  24. nd.setTitle(title);
  25. nd.setSummary(summary);
  26. nd.setContent(content);
  27. nd.setAuthor("admin");
  28. nd.setCreateDate(new Date());
  29. nd.setModifyDate(new Date());
  30. int i=ns.insert(nd);
  31. if(i>0){
  32. //成功跳转到列表页
  33. response.sendRedirect(request.getContextPath()+"/news/newsDetailList.jsp");
  34. }else{
  35. //失败跳转到error页
  36. response.sendRedirect(request.getContextPath()+"/web42/news/error.jsp");
  37. }
  38. %>
  39. </body>
  40. </html>

deleteNewsDetail:

  1. <%@page import="cn.bdqn.pojo.NewsDetail"%>
  2. <%@page import="cn.bdqn.services.impl.NewsServicesImpl"%>
  3. <%@page import="cn.bdqn.services.NewsServices"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <body>
  13. <%
  14. String id=request.getParameter("id");
  15. NewsServices ns=new NewsServicesImpl();
  16. int i=ns.delete(Integer.parseInt(id));
  17. if(i>0){
  18. //成功跳转到列表页
  19. response.sendRedirect(request.getContextPath()+"/news/newsDetailList.jsp");
  20. }else{
  21. //失败跳转到error页
  22. response.sendRedirect(request.getContextPath()+"/web42/news/error.jsp");
  23. }
  24. %>
  25. </body>
  26. </html>

newsDetailList:

  1. <%@page import="cn.bdqn.pojo.NewsDetail"%>
  2. <%@page import="java.util.List"%>
  3. <%@page import="cn.bdqn.services.impl.NewsServicesImpl"%>
  4. <%@page import="cn.bdqn.services.NewsServices"%>
  5. <%@ page language="java" contentType="text/html; charset=UTF-8"
  6. pageEncoding="UTF-8"%>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <title>Insert title here</title>
  12. </head>
  13. <style>
  14. td{
  15. border:black solid 1px
  16. }
  17. </style>
  18. <script type="text/javascript">
  19. function deleteNews(id){
  20. var url="deleteNewsDetail.jsp?id="+id;
  21. var f=confirm("是否确认删除");
  22. if(f){
  23. location.href=url;
  24. }
  25. }
  26. </script>
  27. <body>
  28. <a href="addNewsDetail.jsp">添加</a>
  29. <table style="border:black solid 1px;border-collapse: collapse;">
  30. <tr>
  31. <td>id</td>
  32. <td>标题</td>
  33. <td colspan="2">操作</td>
  34. </tr>
  35. <%
  36. NewsServices ns=new NewsServicesImpl();
  37. List<NewsDetail> list=ns.getNewsDetailList();
  38. for(int i=0;i<list.size();i++){
  39. NewsDetail nd=list.get(i);
  40. %>
  41. <tr>
  42. <td><%=nd.getId() %></td>
  43. <td><%=nd.getTitle() %></td>
  44. <td><a href="upDateNewsDetail.jsp?id=<%=nd.getId() %>">修改</a></td>
  45. <td><a href="javascript:deleteNews(<%=nd.getId() %>)">删除</a></td>
  46. </tr>
  47. <%}%>
  48. </table>
  49. </body>
  50. </html>

upDatenNewsDetail:

  1. <%@page import="cn.bdqn.pojo.NewsDetail"%>
  2. <%@page import="cn.bdqn.services.impl.NewsServicesImpl"%>
  3. <%@page import="cn.bdqn.services.NewsServices"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <body>
  13. <%
  14. String id=request.getParameter("id");
  15. NewsServices ns=new NewsServicesImpl();
  16. NewsDetail nd=ns.getNewsDetailById(Integer.parseInt(id));
  17. %>
  18. <form action="upDateNewsDetailSubmit.jsp" method="post">
  19. 新闻类别:
  20. <select name="categoryId">
  21. <option value="1" <%if(nd.getCategoryId()==1){ %>selected="selected"<%} %>>国内</option>
  22. <option value="2" <%if(nd.getCategoryId()==2){ %>selected="selected"<%} %>>国际</option>
  23. <option value="3" <%if(nd.getCategoryId()==3){ %>selected="selected"<%} %>>娱乐</option>
  24. <option value="4" <%if(nd.getCategoryId()==4){ %>selected="selected"<%} %>>军事</option>
  25. <option value="5" <%if(nd.getCategoryId()==5){ %>selected="selected"<%} %>>财经</option>
  26. <option value="6" <%if(nd.getCategoryId()==6){ %>selected="selected"<%} %>>天气</option>
  27. </select><br/>
  28. 新闻标题:
  29. <input type="text" name="title" value="<%=nd.getTitle() %>"><br/>
  30. 新闻摘要:
  31. <input type="text" name="summary" value="<%=nd.getSummary() %>"><br/>
  32. 新闻内容:
  33. <textarea rows="20" cols="40" name="content" ><%=nd.getContent()%></textarea><br/>
  34. <input type="hidden" name="id" value="<%=id %>">
  35. <input type="submit" value="保存">
  36. </form>
  37. </body>
  38. </html>

upDateNewsDetailSubmit:

  1. <%@page import="java.util.Date"%>
  2. <%@page import="cn.bdqn.pojo.NewsDetail"%>
  3. <%@page import="cn.bdqn.services.impl.NewsServicesImpl"%>
  4. <%@page import="cn.bdqn.services.NewsServices"%>
  5. <%@ page language="java" contentType="text/html; charset=UTF-8"
  6. pageEncoding="UTF-8"%>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <title>Insert title here</title>
  12. </head>
  13. <body>
  14. <%
  15. request.setCharacterEncoding("UTF-8");
  16. response.setCharacterEncoding("UTF-8");
  17. String id=request.getParameter("id");
  18. String categoryId=request.getParameter("categoryId");
  19. String title=request.getParameter("title");
  20. String summary=request.getParameter("summary");
  21. String content=request.getParameter("content");
  22. NewsServices ns=new NewsServicesImpl();
  23. NewsDetail nd=new NewsDetail();
  24. nd.setId(Integer.parseInt(id));
  25. nd.setCategoryId(Integer.parseInt(categoryId));
  26. nd.setTitle(title);
  27. nd.setSummary(summary);
  28. nd.setContent(content);
  29. nd.setAuthor("admin");
  30. nd.setModifyDate(new Date());
  31. int i=ns.update(nd) ;
  32. if(i>0){
  33. //成功跳转到列表页
  34. response.sendRedirect(request.getContextPath()+"/news/newsDetailList.jsp");
  35. }else{
  36. //失败跳转到error页
  37. response.sendRedirect(request.getContextPath()+"/web42/news/error.jsp");
  38. }
  39. %>
  40. </body>
  41. </html>

error:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <h1>操作异常</h1>
  11. </body>
  12. </html>

二、用户表实现

addNewsUser/addNewsUserSubmit/deleteNewsUser/newsUserList/upDateUser/upDateUserSubmit/
addNewsUser:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <form action="addNewsUserSubmit.jsp " method="post">
  11. 姓名:
  12. <input type="text" name="userName"><br/>
  13. 密码:
  14. <input type="text" name="password"><br/>
  15. 邮箱:
  16. <input type="text" name="email"><br>
  17. 用户类型:
  18. <input type="text" name="userType"><br/>
  19. <input type="submit" value="保存">
  20. </form>
  21. </body>
  22. </html>

addNewsUserSubmit:

  1. <%@page import="cn.bdqn.pojo.NewsUser"%>
  2. <%@page import="cn.bdqn.services.impl.userServicesImpl"%>
  3. <%@page import="cn.bdqn.services.userServices"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <body>
  13. <%
  14. request.setCharacterEncoding("UTF-8");
  15. response.setCharacterEncoding("UTF-8");
  16. //获得参数
  17. String id=request.getParameter("id");
  18. String userName=request.getParameter("userName");
  19. String password=request.getParameter("password");
  20. String email=request.getParameter("email");
  21. String userType=request.getParameter("userType");
  22. //接口实现
  23. userServices ns=new userServicesImpl();
  24. //实体类
  25. NewsUser nu=new NewsUser();
  26. //参数添加到实体类
  27. nu.setUserName(userName);
  28. nu.setPassword(password);
  29. nu.setEmail(email);
  30. nu.setUserType(Integer.parseInt(userType));
  31. int i=ns.insert(nu);
  32. if(i>0){
  33. //成功跳转到列表页
  34. response.sendRedirect(request.getContextPath()+"/newsuser/newsUserList.jsp");
  35. }else{
  36. //失败跳转到error页
  37. response.sendRedirect(request.getContextPath()+"/web42/news/error.jsp");
  38. }
  39. %>
  40. </body>
  41. </html>

deleteNewsUser:

  1. <%@page import="cn.bdqn.services.impl.userServicesImpl"%>
  2. <%@page import="cn.bdqn.services.userServices"%>
  3. <%@ page language="java" contentType="text/html; charset=UTF-8"
  4. pageEncoding="UTF-8"%>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title>Insert title here</title>
  10. </head>
  11. <body>
  12. <%
  13. String id=request.getParameter("id");
  14. userServices us=new userServicesImpl();
  15. int i=us.delete(Integer.parseInt(id));
  16. if(i>0){
  17. //成功跳转到列表页
  18. response.sendRedirect(request.getContextPath()+"/newsuser/newsUserList.jsp");
  19. }else{
  20. //失败跳转到error页
  21. response.sendRedirect(request.getContextPath()+"/news/error.jsp");
  22. }
  23. %>
  24. </body>
  25. </html>

newsUserList:

  1. <%@page import="cn.bdqn.pojo.NewsUser"%>
  2. <%@page import="java.util.List"%>
  3. <%@page import="cn.bdqn.services.impl.userServicesImpl"%>
  4. <%@page import="cn.bdqn.services.userServices"%>
  5. <%@ page language="java" contentType="text/html; charset=UTF-8"
  6. pageEncoding="UTF-8"%>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <title>Insert title here</title>
  12. </head>
  13. <style>
  14. td{
  15. border:black solid 1px
  16. }
  17. </style>
  18. <script type="text/javascript">
  19. function deleteUser(id){
  20. var url="deleteNewsUser.jsp?id="+id;
  21. var f=confirm("是否确认删除");
  22. if(f){
  23. location.href=url;
  24. }
  25. }
  26. </script>
  27. <body>
  28. <a href="addNewsUser.jsp">添加</a>
  29. <table style="border:black solid 1px;border-collapse: collapse;">
  30. <tr>
  31. <td>id</td>
  32. <td>姓名</td>
  33. <td>邮箱</td>
  34. <td>用户类型</td>
  35. <td colspan="2">操作</td>
  36. </tr>
  37. <%
  38. userServices ns=new userServicesImpl();
  39. List<NewsUser> list=ns.getNewsUserList();
  40. for(int i=0;i<list.size();i++){
  41. NewsUser nu=list.get(i);
  42. %>
  43. <tr>
  44. <td><%=nu.getId() %></td>
  45. <td><%=nu.getUserName() %></td>
  46. <td><%=nu.getEmail() %></td>
  47. <td><%=nu.getUserType() %></td>
  48. <td><a href="upDateUser.jsp?id=<%=nu.getId() %>">修改</a></td>
  49. <td><a href="javascript:deleteUser(<%=nu.getId() %>)">删除</a></td>
  50. </tr>
  51. <%}%>
  52. </table>
  53. </body>
  54. </html>

upDateUser:

  1. <%@page import="cn.bdqn.pojo.NewsUser"%>
  2. <%@page import="cn.bdqn.services.userServices"%>
  3. <%@page import="cn.bdqn.services.impl.userServicesImpl"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <body>
  13. <%
  14. String id=request.getParameter("id");
  15. userServices ns=new userServicesImpl();
  16. NewsUser nu=ns.getNewsUserById(Integer.parseInt(id));
  17. %>
  18. <form action="upDateUserSubmit.jsp" method="post">
  19. 姓名:
  20. <input type="text" name="userName" value="<%=nu.getUserName() %>"><br/>
  21. 密码:
  22. <input type="text" name="password" value="<%=nu.getPassword() %>"><br/>
  23. 邮箱:
  24. <input type="text" name="email" value="<%=nu.getEmail() %>"><br>
  25. 用户类型:
  26. <input type="text" name="userType" value="<%=nu.getUserType() %>"><br/>
  27. <input type="submit" value="保存">
  28. </form>
  29. </body>
  30. </html>

upDateUserSubmit:

  1. <%@page import="cn.bdqn.pojo.NewsUser"%>
  2. <%@page import="cn.bdqn.services.impl.userServicesImpl"%>
  3. <%@page import="cn.bdqn.services.userServices"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <body>
  13. <%
  14. request.setCharacterEncoding("UTF-8");
  15. response.setCharacterEncoding("UTF-8");
  16. String id=request.getParameter("id");
  17. String userName=request.getParameter("userName");
  18. String password=request.getParameter("password");
  19. String email=request.getParameter("email");
  20. String userType=request.getParameter("userType");
  21. userServices ns=new userServicesImpl();
  22. NewsUser nu=new NewsUser();
  23. nu.setId(Integer.parseInt(id));
  24. nu.setUserName(userName);
  25. nu.setPassword(password);
  26. nu.setEmail(email);
  27. nu.setUserType(Integer.parseInt(userType));
  28. int i=ns.update(nu);
  29. if(i>0){
  30. //成功跳转到列表页
  31. response.sendRedirect(request.getContextPath()+"/newsuser/newsUserList.jsp");
  32. }else{
  33. //失败跳转到error页
  34. response.sendRedirect(request.getContextPath()+"/web42/news/error.jsp");
  35. }
  36. %>
  37. </body>
  38. </html>