基于javaweb+mysql的jsp+servlet新闻管理系统(java+javaweb+jdbc)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet新闻管理系统(java+javaweb+jdbc)
功能介绍:
登录、注册、新闻发布、新闻管理、公告发布、用户管理、退出登录
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>新闻id错误</a>");
out.println("</body></html>");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class updatePassword extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=deleteNews.jsp align=center>输入的新闻ID错误</a>");
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
response.sendRedirect("deleteNews.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class insertNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String title=request.getParameter("title");
byte titles[]=title.getBytes("ISO-8859-1");
title=new String(titles);
String nid=request.getParameter("nid");
byte nids[]=nid.getBytes("ISO-8859-1");
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
PrintWriter out=response.getWriter();
User user=new User();
user.getConn();
if(user.findNamePassword(name, old_pwd)){
if(user.findName(name)){
user.update(name, new_pwd);
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
response.sendRedirect("passwordupdate.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>新闻id错误</a>");
out.println("</body></html>");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class updatePassword extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
String nid=request.getParameter("nid");
byte nids[]=nid.getBytes("ISO-8859-1");
nid=new String(nids);
String content=request.getParameter("content");
byte contents[]=content.getBytes("ISO-8859-1");
content=new String(contents);
String time=request.getParameter("time");
try{
int uid=Integer.parseInt(id);
News news=new News();
news.getConn();
if(news.findID(uid)){
news.Update(uid, title, nid, content,time);
response.sendRedirect("manage.jsp");
}
else{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>该新闻不存在</a>");
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>新闻id错误</a>");
out.println("</body></html>");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
throws ServletException,IOException{
doPost(request,response);
}
}
public class updatePassword extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
PrintWriter out=response.getWriter();
User user=new User();
user.getConn();
if(user.findNamePassword(name, old_pwd)){
public class updateNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String id=request.getParameter("uid");
String title=request.getParameter("title");
byte titles[]=title.getBytes("ISO-8859-1");
title=new String(titles);
String nid=request.getParameter("nid");
byte nids[]=nid.getBytes("ISO-8859-1");
nid=new String(nids);
String content=request.getParameter("content");
byte contents[]=content.getBytes("ISO-8859-1");
content=new String(contents);
String time=request.getParameter("time");
try{
int uid=Integer.parseInt(id);
News news=new News();
news.getConn();
if(news.findID(uid)){
news.Update(uid, title, nid, content,time);
response.sendRedirect("manage.jsp");
}
else{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>该新闻不存在</a>");
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
PrintWriter out=response.getWriter();
out.println("<html>");
public class updatePassword extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
PrintWriter out=response.getWriter();
User user=new User();
user.getConn();
if(user.findNamePassword(name, old_pwd)){
if(user.findName(name)){
user.update(name, new_pwd);
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
news.getConn();
if(news.findID(uid)){
news.delete(uid);
response.sendRedirect("manage.jsp");
}
else{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=deleteNews.jsp align=center>输入的新闻ID错误</a>");
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
response.sendRedirect("deleteNews.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class insertNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
if(user.findName(name)){
user.update(name, new_pwd);
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
response.sendRedirect("passwordupdate.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class deleteNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=deleteNews.jsp align=center>输入的新闻ID错误</a>");
out.println("</body></html>");
}
}
catch (Exception e) {
// TODO: handle exception
response.sendRedirect("deleteNews.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class insertNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String title=request.getParameter("title");
byte titles[]=title.getBytes("ISO-8859-1");
title=new String(titles);
String nid=request.getParameter("nid");
byte nids[]=nid.getBytes("ISO-8859-1");
nid=new String(nids);
String content=request.getParameter("content");
byte contents[]=content.getBytes("ISO-8859-1");
content=new String(contents);
String time=request.getParameter("time");
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
PrintWriter out=response.getWriter();
User user=new User();
user.getConn();
if(user.findNamePassword(name, old_pwd)){
if(user.findName(name)){
user.update(name, new_pwd);
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
response.sendRedirect("passwordupdate.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class updateNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String id=request.getParameter("uid");
String title=request.getParameter("title");
byte titles[]=title.getBytes("ISO-8859-1");
title=new String(titles);
String nid=request.getParameter("nid");
byte nids[]=nid.getBytes("ISO-8859-1");
nid=new String(nids);
String content=request.getParameter("content");
byte contents[]=content.getBytes("ISO-8859-1");
content=new String(contents);
String time=request.getParameter("time");
try{
int uid=Integer.parseInt(id);
News news=new News();
news.getConn();
if(news.findID(uid)){
news.Update(uid, title, nid, content,time);
response.sendRedirect("manage.jsp");
}
else{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>该新闻不存在</a>");
out.println("</body></html>");
}
}
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class deleteNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String id=request.getParameter("uid");
try{
int uid=(int)Integer.parseInt(id);
News news=new News();
news.getConn();
if(news.findID(uid)){
news.delete(uid);
response.sendRedirect("manage.jsp");
}
else{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
}
}
catch (Exception e) {
// TODO: handle exception
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=manage.jsp align=center>新闻id错误</a>");
out.println("</body></html>");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class updatePassword extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String name=request.getParameter("name");
byte names[]=name.getBytes("ISO-8859-1");
name=new String(names);
String old_pwd=request.getParameter("old_pwd");
String new_pwd=request.getParameter("new_pwd");
PrintWriter out=response.getWriter();
User user=new User();
user.getConn();
if(user.findNamePassword(name, old_pwd)){
if(user.findName(name)){
user.update(name, new_pwd);
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
response.sendRedirect("passwordupdate.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
out.print("<body>");
out.print("<a href=login.jsp align=center>密码修改成功</a>");
out.println("</body></html>");
}
else{
out.println("<html>");
out.println("<head>");
out.print("<style>a:link,a:visited,a:hover,a:active{text-decoration: none;color:53bcf8;align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<a href=passwordupdate.jsp align=center>该用户不存在</a>");
out.println("</body></html>");
}
}
else{
response.sendRedirect("passwordupdate.jsp");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}
}
public class deleteNews extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
String id=request.getParameter("uid");
try{