基于javaweb+mysql的jsp+servlet新闻管理系统(java+javaweb+jdbc)

基于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>");
	 		}
	    	 
	     }
	 public  void  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

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.println("</body></html>"); 
		     }
	     }
	     else{
	    	 response.sendRedirect("passwordupdate.jsp");	 
	     }
	   } 
	 public  void  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

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>");
		    	 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);
	 }
	 

}
package Servlet;

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)){

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>");
			 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);
	 }
	 

}
package Servlet;

	 

}
package Servlet;

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>");
			 out.print("</head>");
			 out.print("<body>");
			 out.print("<a href=deleteNews.jsp align=center>输入的新闻ID错误</a>");
			 out.println("</body></html>");
	  	}
	  	}
	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>");
			 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);
	 }
	 

}
package Servlet;

public class insertNews extends HttpServlet{
		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");
		  
		  News news=new News();
		  news.getConn();
		  news.insertUser(title,nid,content,time);
		  response.sendRedirect("insertNews.jsp");
	   } 
	 public  void  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

public class insertMessage extends HttpServlet {

	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
	}
	public void  doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		response.setContentType("text/html;charset=utf-8");
	 public  void  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

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  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

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>");

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>");
			 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);
	 }
	 

}
package Servlet;
				 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);
	 }
	 

}
package Servlet;

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);	  		

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 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>");
			 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{
		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);
	 }
	 

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>");
			 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);
	      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");
		  
		  News news=new News();
		  news.getConn();
		  news.insertUser(title,nid,content,time);
		  response.sendRedirect("insertNews.jsp");
	   } 
	 public  void  doGet(HttpServletRequest request,HttpServletResponse response) 
     throws ServletException,IOException{
		 doPost(request,response);
	 }
	 

}
package Servlet;

public class insertMessage extends HttpServlet {

	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
	}
	public void  doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		response.setContentType("text/html;charset=utf-8");
		
		String content=request.getParameter("content");
		byte contents[]=content.getBytes("ISO-8859-1");
		content=new String(contents);
		
		message mess=new message();

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>");
	 			 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>");

请添加图片描述

请添加图片描述
请添加图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值