${querySig.title }:${querySig.summary } | |
${querySig.addtime } | ${querySig.author } |
${querySig.content } | |
${sa.content } | |||||
目录
一、登录
二、主页
四、删除新闻
五、增加新闻
六、阅读新闻
七、修改新闻
开发流程思维导图
项目使用:毕业设计、课程设计、大作业、项目练习、学习演示等...
想要源码的童鞋可以+本人QQ:203114746、QQ邮箱:[email protected]、想学习的童鞋或者对IT行业感兴趣的也可以找我请教哦!!!本人是一个很热情的男孩子喔
1.前端登录页面jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
用户登录
2.处理登录功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.IUsersBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.biz.imp.UsersBiz;
import com.jmh.dao.imp.UsersDao;
import com.jmh.entity.Users;
import com.jmh.entity.news;
/**
* 登录的servlet程序
* @author 蒋明辉
*
*/
public class LoginServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取out session对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//获取前端带过来的值
String uname=req.getParameter("uname");
String upwd=req.getParameter("upwd");
//处理业务逻辑代码
//登录功能
//实例化实体类
Users u=new Users();
u.setUname(uname);//账户
u.setUpwd(upwd);//密码
IUsersBiz iub=new UsersBiz();
try {
boolean login = iub.login(u);
if(login) {//登录成功
//把用户名传进session作用域里面
session.setAttribute("uname", uname);
req.getRequestDispatcher("/admin/admin.jsp").forward(req, resp);
}else {//登录失败
out.print("");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
1.前端主页页面jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
添加主题--管理后台
欢迎使用新闻管理系统!
管理员: ${uname } 注销/退出
2,处理绑定新闻信息/模糊查询新闻信息功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.NetworkInterface;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.entity.news;
/**
* 查询全部信息/模糊查询
* @author 蒋明辉
*
*/
public class QueryServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取out session对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//处理业务逻辑代码
INewsBiz inb=new NewsBiz();
try {
//获取模糊查询里面的字段
String title = req.getParameter("title");
//非空
if(null==title||"".equals(title)) {
title="";
}
List query = inb.queryLike(title);
if(query.size()<1) {//当集合没有值
List querys = inb.queryLike("");
//把集合保存到req作用域里面
req.setAttribute("query", querys);
req.getRequestDispatcher("admin/admin.jsp").forward(req, resp);
return;
}
//把集合保存到req作用域里面
req.setAttribute("query", query);
req.getRequestDispatcher("admin/admin.jsp").forward(req, resp);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
3.处理注销/退出功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* 注销/退出
* @author 蒋明辉
*
*/
public class SessionOut extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取out session对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//处理业务逻辑代码
session.invalidate();
resp.sendRedirect(req.getContextPath()+"/admin/login.jsp");
}
}
处理删除新闻功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.imp.NewsBiz;
/**
* 删除新闻
* @author 蒋明辉
*
*/
public class DeleteServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session = req.getSession();
PrintWriter out=resp.getWriter();
//处理业务逻辑代码
//获取删除对象
String nid=req.getParameter("nid");
INewsBiz inb=new NewsBiz();
try {
int delete = inb.delete(nid);
if(delete>0) {//删除成功
resp.sendRedirect(req.getContextPath()+"/queryServlet.do");
}else {//删除失败
out.print(req.getContextPath()+"/admin/admin.jsp");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
1.前端增加页面jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
添加主题--管理后台
欢迎使用新闻管理系统!
管理员: ${uname } 注销/退出
添加新闻:
2.处理绑定主题功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.ISubJectsBiz;
import com.jmh.biz.imp.SubJectsBiz;
import com.jmh.entity.Subjects;
/**
* 查询新闻主题
* @author 蒋明辉
*
*/
public class QuerySubJectsServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//处理业务逻辑代码
ISubJectsBiz isu=new SubJectsBiz();
//调用方法
try {
List query = isu.query();
//保存到作用域里面
req.setAttribute("query", query);
//转发
req.getRequestDispatcher("/admin/news_add.jsp").forward(req, resp);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
3.处理增加新闻功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.entity.news;
/**
* 增加新闻
* @author 蒋明辉
*
*/
public class InsertServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//处理业务逻辑代码
String sid= req.getParameter("zt");
String bt= req.getParameter("bt");
String zz= req.getParameter("zz");
String zy= req.getParameter("zy");
String nr= req.getParameter("nr");
String sctp= req.getParameter("sctp");
/* System.out.println(bt);
System.out.println(zz);
System.out.println(zy);
System.out.println(nr);
System.out.println(sctp);*/
//调用方法
INewsBiz inb=new NewsBiz();
//实例化对象
news news=new news(Integer.parseInt(sid), bt, zz, zy, nr, sctp);
try {
int insert = inb.insert(news);
if(insert>0) {//增加成功
resp.sendRedirect(req.getContextPath()+"/queryServlet.do");//绑定数据servlet程序
}else {//增加失败
out.print("");//原地
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
1.阅读和修改我们都需要绑定信息所有我们简化了多余的代码通过带参来判断是要跳转阅读还是修改。。。
处理绑定要阅读的信息功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.ISubJectsBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.biz.imp.SubJectsBiz;
import com.jmh.entity.Subjects;
import com.jmh.entity.news;
/**
* 新闻的单个查询
* @author 蒋明辉
*
*/
public class QuerySigServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session=req.getSession();
PrintWriter out = resp.getWriter();
//获取前端传过来的新闻编号
String parameter = req.getParameter("nid");
//获取查询新闻的编号
INewsBiz inb=new NewsBiz();
try {
news querySig = inb.querySig(parameter);
//将作用存进作用域里面
req.setAttribute("querySig", querySig);
//拿到前端带过来的指定调到哪里的参数
String parameter2 = req.getParameter("function");
if(parameter2.equals("yd")) {//点击的是阅读
//跳转到阅读页面
req.getRequestDispatcher("/admin/news_read.jsp").forward(req, resp);
}else {//是修改
ISubJectsBiz isu=new SubJectsBiz();
List query = isu.query();
//保存到作用域里面
req.setAttribute("query", query);
//跳转到修改页面
req.getRequestDispatcher("/admin/news_update.jsp").forward(req, resp);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
2.前端阅读页面jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
新闻中国
<%--
--%>
${querySig.title }:${querySig.summary }
${querySig.addtime }
${querySig.author }
${querySig.content }
${sa.content }
3.处理绑定新闻评论功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.StandardSocketOptions;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.ICommentsBiz;
import com.jmh.biz.imp.CommentsBiz;
import com.jmh.dao.imp.NewsDao;
import com.jmh.entity.Comments;
/**
* 根据新闻编号查询评论/展示评论
* @author 蒋明辉
*
*/
public class QueryCommentsServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session = req.getSession();
PrintWriter out=resp.getWriter();
//处理业务逻辑代码
//获取值
String nid = req.getParameter("nid");
ICommentsBiz icb=new CommentsBiz();
try {
//定义一个集合
List
4.处理发表评论功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.ICommentsBiz;
import com.jmh.biz.imp.CommentsBiz;
import com.jmh.dao.imp.CommentsDao;
import com.jmh.entity.Comments;
/**
* 增加新闻评论的程序
* @author 蒋明辉
*
*/
public class InsertCommentsServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session = req.getSession();
PrintWriter out = resp.getWriter();
//获取发表评论的值
String nid=req.getParameter("nid");
String yhp=req.getParameter("yhm");
String ip=req.getParameter("ip");
String nr=req.getParameter("nr");
/* System.out.println(yhp);
System.out.println(ip);
System.out.println(nr);
System.out.println(nid);*/
//调用增加的方法
ICommentsBiz icb=new CommentsBiz();
//实例化实体类
Comments c=new Comments();
c.setNid(Integer.parseInt(nid));
c.setUname(yhp);
c.setUip(ip);
c.setContent(nr);
try {
int insert = icb.insert(c);
if(insert>0) {
//增加成功跳转到根据新闻编号查询评论的servlet
req.getRequestDispatcher("/querySigServlet.do?function=yd&nid="+nid+"").forward(req, resp);
}else {//跳转阅读页面
out.print("");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
1.处理绑定要修改的信息功能
package com.jmh.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.ISubJectsBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.biz.imp.SubJectsBiz;
import com.jmh.entity.Subjects;
import com.jmh.entity.news;
/**
* 新闻的单个查询
* @author 蒋明辉
*
*/
public class QuerySigServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session=req.getSession();
PrintWriter out = resp.getWriter();
//获取前端传过来的新闻编号
String parameter = req.getParameter("nid");
//获取查询新闻的编号
INewsBiz inb=new NewsBiz();
try {
news querySig = inb.querySig(parameter);
//将作用存进作用域里面
req.setAttribute("querySig", querySig);
//拿到前端带过来的指定调到哪里的参数
String parameter2 = req.getParameter("function");
if(parameter2.equals("yd")) {//点击的是阅读
//跳转到阅读页面
req.getRequestDispatcher("/admin/news_read.jsp").forward(req, resp);
}else {//是修改
ISubJectsBiz isu=new SubJectsBiz();
List query = isu.query();
//保存到作用域里面
req.setAttribute("query", query);
//跳转到修改页面
req.getRequestDispatcher("/admin/news_update.jsp").forward(req, resp);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
2.前端修改页面jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
修改主题--管理后台
<%--
--%>
欢迎使用新闻管理系统!
管理员: ${uname } 注销/退出
修改新闻:
3.处理修改新闻功能
package com.jmh.servlet;
/**
* 修改新闻
* @author 蒋明辉
*
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jmh.biz.INewsBiz;
import com.jmh.biz.imp.NewsBiz;
import com.jmh.entity.news;
public class UpdateNewsServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取对象
HttpSession session=req.getSession();
PrintWriter out=resp.getWriter();
//处理业务逻辑代码
//接收前端填入的值
String nid=req.getParameter("nid");
String zt=req.getParameter("zt");
String bt=req.getParameter("bt");
String zz=req.getParameter("zz");
String zy=req.getParameter("zy");
String nr=req.getParameter("nr");
//调用修改的方法
INewsBiz inb=new NewsBiz();
//实体化一个对象
news news=new news(Integer.parseInt(nid), Integer.parseInt(zt), bt, zz, zy, nr);
try {
int update = inb.update(news);
if(update>0) {
//修改成功
//跳转到绑定数据的servlet
req.getRequestDispatcher("/queryServlet.do").forward(req, resp);;
}else {
//修改失败
//跳转到单个查询的servlet
out.print("");
}
} catch (SQLException e) {
e.printStackTrace();
}
/* System.out.println("新闻编号="+nid);
System.out.println("新闻主题="+zt);
System.out.println("新闻标题="+bt);
System.out.println("新闻作者="+zz);
System.out.println("新闻摘要="+zy);
System.out.println("新闻内容="+nr);*/
}
}
项目演示
项目使用:毕业设计、课程设计、大作业、项目练习、学习演示等...
想要源码的童鞋可以+本人QQ:203114746、QQ邮箱:[email protected]、想学习的童鞋或者对IT行业感兴趣的也可以找我请教哦!!!本人是一个很热情的男孩子喔