ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [MessageSystem] Controller_Class
    JSP Servlet 2022. 7. 15. 15:16

    1. JoinService

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="com.smhrd.model.BoardDAO">
    	<insert id="boardInsert" parameterType="BoardVO">
    		insert into messageboard
    		values(num_board.nextval,#{title},#{writer},#{filename},#{content},sysdate)
    	</insert>
    	<select id="boardSelect" resultType="BoardVO">
    		select * from messageboard order by b_day desc
    	</select>
    		<select id="boarddetail" resultType="BoardVO">
    		select * from messageboard where num = #{num}
    	</select>
    	<delete id="boarddelete" parameterType="String">
    		delete from messageboard where num=#{num}
    	</delete>
    </mapper>

     

    2. LoginService

    package com.smhrd.controller_class;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import com.smhrd.command.Command;
    import com.smhrd.model.DAO;
    import com.smhrd.model.MemberVO;
    
    public class LoginService implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		String email = request.getParameter("email");
    		String pw = request.getParameter("pw");
    
    		MemberVO vo = new MemberVO(email, pw, null, null);
    		DAO dao = new DAO();
    
    		MemberVO result = dao.Login(vo);
    		if (result != null) {
    			HttpSession session = request.getSession();
    			session.setAttribute("member", result);
    		}else {
    			
    		}
    		return "main.jsp";
    	}
    
    }

     

    3. LogoutService

    package com.smhrd.controller_class;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import javax.websocket.Session;
    
    import com.smhrd.command.Command;
    
    public class LogoutService implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		HttpSession session = request.getSession();
    		session.invalidate();
    		return "main.jsp";
    	}
    
    }

     

    4. UpdateService

    package com.smhrd.controller_class;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import com.smhrd.command.Command;
    import com.smhrd.model.DAO;
    import com.smhrd.model.MemberVO;
    
    public class UpdateService implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		String email = request.getParameter("email");
    		String pw = request.getParameter("pw");
    		String phone = request.getParameter("phone");
    		String address = request.getParameter("address");
    
    		MemberVO vo = new MemberVO(email, pw, phone, address);
    
    		DAO dao = new DAO();
    
    		int row = dao.Update(vo);
    
    		if (row > 0) {
    			System.out.println("회원정보 수정 성공");
    			HttpSession session = request.getSession();
    			session.setAttribute("member", vo);
    		}
    		return "main.jsp";
    	}
    
    }

     

    5. DeleteService

    package com.smhrd.controller_class;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.smhrd.command.Command;
    import com.smhrd.model.DAO;
    
    public class DeleteService implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		String email = request.getParameter("email");
    		System.out.println(email);
    
    		DAO dao = new DAO();
    		int row = dao.delete(email);
    
    		if (row > 0) {
    			System.out.println("회원 삭제 성공");
    		}
    		return "select.jsp";
    	}
    
    }

     

    6. WriterBoardService

    package com.smhrd.controller_class;
    
    import java.net.URLEncoder;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.oreilly.servlet.MultipartRequest;
    import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
    import com.smhrd.command.Command;
    import com.smhrd.model.BoardDAO;
    import com.smhrd.model.BoardVO;
    
    public class WriterBoardServce implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		String path = request.getServletContext().getRealPath("file");
    		System.out.println(path);
    		int maxSize = 10 * 1024 * 1024;
    		String encoding = "UTF-8";
    		DefaultFileRenamePolicy rename = new DefaultFileRenamePolicy();
    		try {
    			MultipartRequest multi = new MultipartRequest(request, path, maxSize, encoding, rename);
    
    			String title = multi.getParameter("title");
    			String writer = multi.getParameter("writer");
    			String filename = multi.getFilesystemName("filename");
    			filename = URLEncoder.encode(filename, "UTF-8");
    			String content = multi.getParameter("content");
    
    			BoardVO vo = new BoardVO(title, writer, filename, content);
    			BoardDAO dao = new BoardDAO();
    			int row = dao.upload(vo);
    			if (row > 0) {
    				System.out.println("업로드 성공");
    			}else {
    				
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return "boardMain.jsp";
    		} 
    		
    	}

     

    7. DeleteBoardService

    package com.smhrd.controller_class;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.smhrd.command.Command;
    import com.smhrd.model.BoardDAO;
    
    public class DeleteBoardService implements Command {
    
    	@Override
    	public String execute(HttpServletRequest request, HttpServletResponse response) {
    		String num = request.getParameter("num");
    
    		BoardDAO dao = new BoardDAO();
    		int row = dao.delete(num);
    
    		if (row > 0) {
    			System.out.println("게시물 삭제 성공");
    		}
    
    		return "boardMain.jsp";
    	}
    
    }

    'JSP Servlet' 카테고리의 다른 글

    [MessageSystem] Command  (0) 2022.07.15
    [MessageSystem] FrontController  (0) 2022.07.15
    [MessageSystem] DataBase  (0) 2022.07.15
    [MessageSystem] Model  (0) 2022.07.15
    [MessageSystem] ViewBoard.jsp  (0) 2022.07.15

    댓글

Designed by Tistory.