基于java web博客系统的设计与实现

文章目录

  • 前言
  • 一、项目设计
    • 1. 模块设计
    • 2. 实现效果
  • 二、部分源码
  • 项目源码


前言

今天学长向大家分享一个 java web 毕设 项目:

文章发布系统的设计与实现


一、项目设计

1. 模块设计

根据需求分析的结果,文章发布系统主要划分两个子模块后台管理模块,前台门户模块,各模块又包含子模块。分为以下几个模块

  • 界面设计模块
  • 用户注册模块
  • 用户登录模块
  • 文章搜索模块
  • 用户留言模块
  • 用户评论模块
  • 用户信息管理模块
  • 功能管理部分
  • 用户管理模块
  • 公告管理模块
  • 文章管理模块
  • 评论管理模块
  • 留言管理模块
  • 管理员管理模块

基于java web博客系统的设计与实现_第1张图片

2. 实现效果

基于java web博客系统的设计与实现_第2张图片
在这里插入图片描述

在这里插入图片描述

基于java web博客系统的设计与实现_第3张图片
基于java web博客系统的设计与实现_第4张图片
基于java web博客系统的设计与实现_第5张图片
基于java web博客系统的设计与实现_第6张图片
基于java web博客系统的设计与实现_第7张图片
基于java web博客系统的设计与实现_第8张图片

功能较多,学长这里就不一 一展示了

二、部分源码

部分代码示例:

package control;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.RequestContext;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.servlet.ServletRequestContext;


import util.Info;

import dao.CommDAO;

public class MainCtrl extends HttpServlet {

	public MainCtrl() {
	 
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
	this.doPost(request, response);
	}

		public void go(String url,HttpServletRequest request, HttpServletResponse response)
		{
		try {
			request.getRequestDispatcher(url).forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		}
		
		public void gor(String url,HttpServletRequest request, HttpServletResponse response)
		{
			try {
				response.sendRedirect(url);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
        response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String ac = request.getParameter("ac");
		if(ac==null)ac="";
		CommDAO dao = new CommDAO();
		String date = Info.getDateStr();
		String today = date.substring(0,10);
		String tomonth = date.substring(0,7);
		
		//登录
		if(ac.equals("login"))
		{
			String username = request.getParameter("uname");
			String password = request.getParameter("upass");
			String utype = request.getParameter("utype");
			String sql = "select * from sysuser where uname='"+username+"' and upass='"+password+"' and utype='"+utype+"'";
			List<HashMap> userlist = dao.select(sql);
			if(userlist.size()!=1)
			{
			    request.setAttribute("error", "");
				go("/index.jsp", request, response);
			}else{
				request.getSession(). setAttribute("user", userlist.get(0));
				gor("/newspubs/admin/index.jsp", request, response);
			}
		}
		
		if(ac.equals("uploaddoc"))
		{
			try {
				String filename="";
			request.setCharacterEncoding("utf-8");
			RequestContext  requestContext = new ServletRequestContext(request);
			if(FileUpload.isMultipartContent(requestContext)){

			   DiskFileItemFactory factory = new DiskFileItemFactory();
			   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
			   ServletFileUpload upload = new ServletFileUpload(factory);
			   upload.setSizeMax(100*1024*1024);
			   List items = new ArrayList();
			    
			     items = upload.parseRequest(request);
			     
			    FileItem fileItem = (FileItem) items.get(0);
			   if(fileItem.getName()!=null && fileItem.getSize()!=0)
			    {
			    if(fileItem.getName()!=null && fileItem.getSize()!=0){
			      File fullFile = new File(fileItem.getName());
			      filename = Info.generalFileName(fullFile.getName());
			      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
			      try {
			       fileItem.write(newFile);
			      } catch (Exception e) {
			       e.printStackTrace();
			      }
			     }else{
			     }
			    }
			}
			
			go("/js/uploaddoc.jsp?docname="+filename, request, response);
			} catch (Exception e1) {
				e1.printStackTrace();
			    }
		}
		
		//登录
		if(ac.equals("flogin"))
		{
			String username = request.getParameter("uname");
			String password = request.getParameter("upass");
			String utype = request.getParameter("utype");
			String sql = "select * from sysuser where uname='"+username+"' and upass='"+password+"' ";
			List<HashMap> userlist = dao.select(sql);
			if(userlist.size()!=1)
			{
			    request.setAttribute("error", "");
				go("/login.jsp", request, response);
			}else{
				request.getSession(). setAttribute("user", userlist.get(0));
				gor("index.jsp", request, response);
			}
		}
		
		//修改密码
		if(ac.equals("uppass"))
		{
			String pass = request.getParameter("pass");
			String id = request.getParameter("id");
			String sql = "update sysuser set upass='"+pass+"' where id="+id;
			dao.commOper(sql);
			request.setAttribute("suc", "");
			go("/admin/uppass.jsp", request, response);
		}
		
	


		if(ac.equals("adduser"))
		{
			String uname = request.getParameter("uname");
			String upass = request.getParameter("upass");
			String utype = request.getParameter("utype");
			int i = dao.getInt("select count(*) from sysuser where uname='"+uname+"'");
			if(i==0)
			{
			String sql = "insert into sysuser values('"+uname+"','"+upass+"','"+date+"','"+utype+"')";
			dao.commOper(sql);
			}
			gor("/newspubs/admin/adduser.jsp?suc=suc",request,response);
		}
		
		 
		if(ac.equals("upuser"))
		{
			String id = request.getParameter("id");
			String upass = request.getParameter("upass");
			String utype = request.getParameter("utype");
			
			String sql = "update sysuser set upass='"+upass+"',utype='"+utype+"' where id="+id;
			dao.commOper(sql);
			
			go("/admin/upuser.jsp?suc=suc",request,response);
		}
		

		if(ac.equals("uploadimg"))
		{
			try {
				String filename="";
			request.setCharacterEncoding("utf-8");
			RequestContext  requestContext = new ServletRequestContext(request);
			if(FileUpload.isMultipartContent(requestContext)){

			   DiskFileItemFactory factory = new DiskFileItemFactory();
			   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
			   ServletFileUpload upload = new ServletFileUpload(factory);
			   upload.setSizeMax(100*1024*1024);
			   List items = new ArrayList();
			    
			     items = upload.parseRequest(request);
			     
			    FileItem fileItem = (FileItem) items.get(0);
			   if(fileItem.getName()!=null && fileItem.getSize()!=0)
			    {
			    if(fileItem.getName()!=null && fileItem.getSize()!=0){
			      File fullFile = new File(fileItem.getName());
			      filename = Info.generalFileName(fullFile.getName());
			      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
			      try {
			       fileItem.write(newFile);
			      } catch (Exception e) {
			       e.printStackTrace();
			      }
			     }else{
			     }
			    }
			}
			
			go("/js/uploadimg.jsp?filename="+filename, request, response);
			} catch (Exception e1) {
				e1.printStackTrace();
			    }
		}
		
		

		
		
		

		if(ac.equals("uploadimg"))
		{
			try {
				String filename="";
			request.setCharacterEncoding("utf-8");
			RequestContext  requestContext = new ServletRequestContext(request);
			if(FileUpload.isMultipartContent(requestContext)){

			   DiskFileItemFactory factory = new DiskFileItemFactory();
			   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
			   ServletFileUpload upload = new ServletFileUpload(factory);
			   upload.setSizeMax(100*1024*1024);
			   List items = new ArrayList();
			    
			     items = upload.parseRequest(request);
			     
			    FileItem fileItem = (FileItem) items.get(0);
			   if(fileItem.getName()!=null && fileItem.getSize()!=0)
			    {
			    if(fileItem.getName()!=null && fileItem.getSize()!=0){
			      File fullFile = new File(fileItem.getName());
			      filename = Info.generalFileName(fullFile.getName());
			      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
			      try {
			       fileItem.write(newFile);
			      } catch (Exception e) {
			       e.printStackTrace();
			      }
			     }else{
			     }
			    }
			}
			
			go("/js/uploadimg.jsp?filename="+filename, request, response);
			} catch (Exception e1) {
				e1.printStackTrace();
			    }
		}
		
		
		
		dao.close();
		out.flush();
		out.close();
	}


	public void init() throws ServletException {
		// Put your code here
	}
	
	

}

项目源码

https://blog.csdn.net/mabile123444/article/details/119712695

你可能感兴趣的:(java开发,java,web,毕业设计,java,web毕设,博客系统,文章发布系统)