jsp프로젝트 세팅

1. workspace 세팅
- utf-8
- 단축키 세팅
- font 세팅

2.프로젝트 생성
- 다이나믹 웹 프로젝트
- webcontent/index.jsp 파일 생성 및 실행

3. git Repository 생성 및 시작

-------------------------------------

카카오 로그인

 

------------------------------------

구글에서 검색되려면

<meta name="robots">

 

'낙서장' 카테고리의 다른 글

  (0) 2020.06.26
카카오 네이버 연동 계정 탈퇴하기  (0) 2020.06.18
코딩 오류 케어  (0) 2020.06.17
200617  (0) 2020.06.17
웹에디터 ckeditor  (0) 2020.06.16

 

프로그램이 오류가 날 때 확인할 것

1. 오타 + 대소문자확인

2. 각 파트별로 sout 해보기 

'낙서장' 카테고리의 다른 글

카카오 네이버 연동 계정 탈퇴하기  (0) 2020.06.18
200618  (0) 2020.06.18
200617  (0) 2020.06.17
웹에디터 ckeditor  (0) 2020.06.16
vsCode 저장시 자동으로 코드정렬  (0) 2020.06.15

 

ssl서버를 설치를 하면 데이터를 주고받을 때 암호화를 한다.

중요한 사항이 있을경우 사용하도록 권장

 

------------------------------------------

 

'낙서장' 카테고리의 다른 글

200618  (0) 2020.06.18
코딩 오류 케어  (0) 2020.06.17
웹에디터 ckeditor  (0) 2020.06.16
vsCode 저장시 자동으로 코드정렬  (0) 2020.06.15
공부할거  (0) 2020.06.13

 

URLEcoder.encode를 사용하자

 

카카오 로그인 목적

1. 인증
블로그 만드는 것보다 인증절차가 더 복잡한데, 그런 것을 카카오 로그인에서 대신해준다.

2.인증 + 사용자 정보

 

 

 

 

1. 유저가 블로그 서버에 카카오 로그인 요청

2. 카카오 로그인창에서 로그인

3. 카카오 api서버(+리소스서버)에서 인증을 하여 블로그 서버로 인증결과(코드)를 반환

4. 유저가 정보를 제공하지 않겠다면 코드를 블로그 서버로 주고 과정이 끝나고,

5. 유저 정보를 제공하겠다고 체크하면 다시 카카오 서버로 통신하여 토큰을 받아온다.

6. 토큰을 이용하면 블로그 서버에서 바로 리소스 서버로 유저정보 요청이 가능해진다.

7. 리소스 서버에서 가져온 회원정보가 블로그 회원가입 테이블 조건에 부적합하다면
  인증만 된 상태에서 회원가입을 따로 시켜야한다.
  적합하다면 바로 로그인 시키면 된다.

-----------------카카오 입장에서 보았을 때------------------

유저(웹브라우저) = 리소스 오너

블로그 = 클라이언트

카카오api = api 인터페이스 서버

리소스 서버

 

 

 

카카오 개발자 사이트 접속

--------------------------------------------------------------------------

 

 

 

내 애플리케이션에서 애플리케이션 추가를 클릭

 

 

앱키의 종류

 

내 사이트 주소 설정

 

 

 

 

주소입력

 

 

카카오 로그인 활성화

 

 

요청주소 등록

 

 

주소를 설정해준다

 

 

로그아웃 요청

 

 

 

 

동의항목 설정

 

 

 

 

 

 

 

 

 

 

 

문서를 읽어본다

https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api#request-code

 

Kakao Developers

카카오 API를 활용하여 다양한 어플리케이션을 개발해보세요. 카카오 로그인, 메시지 보내기, 친구 API, 인공지능 API 등을 제공합니다.

developers.kakao.com

 

 

 

 

 

 

 

 

GET /oauth/authorize?client_id={app_key}&redirect_uri={redirect_uri}&response_type=code HTTP/1.1
Host: kauth.kakao.com

 

app_key

 

redirect_uri

 

 

https://kauth.kakao.com/oauth/authorize?client_id=아이디&redirect_uri=http://localhost:8000/blog/oauth/kakao?cmd=callback&response_type=code

 

 

결과가 뜸

 

보내면

클라이언트ID
콜백주소
response_type : code
eamil
profile (사진, 닉네임)
유저ID, 비밀번호

 

 

 

더보기
package com.cos.blog.controller;

import java.io.IOException;

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

import com.cos.blog.action.Action;
import com.cos.blog.action.kakao.KakaoCallbackAction;

// http://localhost:8000/blog/board
@WebServlet("/oauth/kakao")
public class KakaoController extends HttpServlet {
	private final static String TAG = "BoardController : ";
	private static final long serialVersionUID = 1L;
       
    public KakaoController() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// http://localhost:8000/blog/user?cmd=join
		String cmd = request.getParameter("cmd");
		System.out.println(TAG+"router : "+cmd);
		Action action = router(cmd);
		action.execute(request, response);
	}
	
	public Action router(String cmd) {
		
		if(cmd.equals("callback")) {
			return new KakaoCallbackAction();
		}
		
		return null;
		
	}
	
}

 

 

 

더보기
package com.cos.blog.action.kakao;

import java.io.IOException;

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

import com.cos.blog.action.Action;

public class KakaoCallbackAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String code = request.getParameter("code");
		System.out.println("카카오 인증 완료됨");
		System.out.println(code);
		
	}

}

 

 

 

POST /oauth/token HTTP/1.1
Host: kauth.kakao.com
Content-type: application/x-www-form-urlencoded;charset=utf-8

kauth.kakao.com/oauth/token  포스트타입

HTTP 1.1 = get post put delete 다가능

Content-type: application/x-www-form-urlencoded;charset=utf-8 타입으로 보내라는 뜻

 

 

 

 

body에 담겨야할 값

grant_type=authorization_code

client_id=내 restapi 키

redirect_uri=http://localhost:8000/blog/oauth/kakao?cmd=callback

code=리턴받은 코드

 

 

-------------------------------

리턴받은 내용을 자동으로 파싱해주는 라이브러리

resttemplate - object wrapper

retrofit2 - gson - 인기 많음

okhttp

volly

-----------------------

httpurlconnection

--------------------------

 

 

 

 

유저정보 가져오기

https://developers.kakao.com/docs/latest/ko/user-mgmt/rest-api

 

Kakao Developers

카카오 API를 활용하여 다양한 어플리케이션을 개발해보세요. 카카오 로그인, 메시지 보내기, 친구 API, 인공지능 API 등을 제공합니다.

developers.kakao.com

 

 

 

 

 

 

 

 

 

부트스트랩 그리드 배치 쉽게 하는 사이트

 

http://shoelace.io/

 

Shoelace - Visual Bootstrap 3 Grid Builder

 

shoelace.io

 

'Web > Html_Css' 카테고리의 다른 글

부트스트랩 사이트 모음  (0) 2020.06.22
그리드 grid 사용법  (0) 2020.06.19
materializecss / w3schools 아이콘 사용  (0) 2020.06.15
div // p // span 차이  (0) 2020.06.11
부트스트랩 가로세로 정렬  (0) 2020.06.10

 

기본구조

 

 

데이터베이스 테이블 추가

팀목록 테이블

CREATE TABLE TEAMLIST 
(
  ID NUMBER NOT NULL 
, TEAMNAME VARCHAR2(50) 
, CONSTRAINT TEAMLIST_PK PRIMARY KEY 
  (
    ID 
  )
  ENABLE 
);

ALTER TABLE TEAMLIST
ADD CONSTRAINT TEAMLIST_UK1 UNIQUE 
(
  TEAMNAME 
)
ENABLE;

 

선수목록 테이블

CREATE TABLE PLAYERLIST 
(
  ID NUMBER NOT NULL 
, PLAYERNUM NUMBER 
, PLAYERNAME VARCHAR2(20) 
, POSITION VARCHAR2(20) 
, TEAMNAME VARCHAR2(50) 
, CONSTRAINT PLAYERLIST_PK PRIMARY KEY 
  (
    ID 
  )
  ENABLE 
);

ALTER TABLE PLAYERLIST
ADD CONSTRAINT PLAYERLIST_FK1 FOREIGN KEY
(
  TEAMNAME 
)
REFERENCES TEAMLIST
(
  TEAMNAME 
)
ON DELETE SET NULL ENABLE;

 

 

index.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	response.sendRedirect("/baseball/team?cmd=home");
%>

 

 

home.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>야구선수 정보</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-sm-3">
       	  <h2>팀 목록</h2>           
		  <table class="table table-hover">
		    <thead>
		      <tr>
		        <th>번호</th>
		        <th>팀 이름</th>
		      </tr>
		    </thead>
		    <tbody>
		    	<c:forEach var="team" items="${teamList}">
			      <tr>
			        <td>${team.id}</td>
			        <td onclick="getPlayer('${team.teamName}')" style="cursor: pointer;">${team.teamName}</td>
			      </tr>
		    	</c:forEach>
		    </tbody>
		  </table>
        </div>
        <div class="col-sm-3">
        	<h2>선수 목록</h2>           
		  <table class="table table-success">
		    <thead>
		      <tr>
		        <th>선수 번호</th>
		        <th>선수 이름</th>
		      </tr>
		    </thead>
		    <tbody id="player__list">
		    </tbody>
		  </table>
        </div>
        <div class="col-sm-6">
        	<h2>선수 상세</h2>           
		  <table class="table table-info">
		    <thead>
		      <tr>
		        <th>선수 번호</th>
		        <th>선수 이름</th>
		        <th>포지션</th>
		      </tr>
		    </thead>
		    <tbody id="player__desc">
		    </tbody>
		  </table>
        </div>
    </div>
</div>

<script type="text/javascript">

	function getPlayer(teamName) {
		$.ajax({
			type: "get",
			url: "/baseball/player?cmd=getPlayer&teamName="+teamName,
			dataType: "json"
		}).done(function(result) {
			
			$("#player__list").empty();
			for (let player of result) {
				var string =
					"			      <tr>\r\n" + 
					"			        <td>"+player.playerNum+"</td>\r\n" + 
					"			        <td onclick=\"getDesc('"+player.playerNum+"','"+teamName+"')\" style=\"cursor: pointer;\">"+player.playerName+"</td>\r\n" + 
					"			      </tr>";
					
				$("#player__list").append(string);
					
			}
			
			$("#player__desc").empty();
			
		}).fail(function(result) {
			alert("검색에 실패하였습니다.");
		});
	}
	
	function getDesc(playerNum, teamName) {
		
		$.ajax({
			type: "get",
			url: "/baseball/player?cmd=getDesc&teamName="+teamName+"&playerNum="+playerNum,
			dataType: "json"
		}).done(function(result) {
			
			$("#player__desc").empty();

			var string =
				"			      <tr>\r\n" + 
				"			        <td>"+result.playerNum+"</td>\r\n" + 
				"			        <td>"+result.playerName+"</td>\r\n" + 
				"			        <td>"+result.position+"</td>\r\n" +
				"			      </tr>";
				
			$("#player__desc").append(string);

		}).fail(function(result) {
			alert("검색에 실패하였습니다.");
		});
		
	}

</script>

</body>
</html>

 

 

Dbconn.java

더보기
package com.jaybon.baseball.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DBConn {
	public static Connection getConnection() {
		try {
			Context initContext = new InitialContext();
			Context envContext = (Context) initContext.lookup("java:/comp/env");
			DataSource ds = (DataSource) envContext.lookup("jdbc/myoracle");
			Connection conn = ds.getConnection();
			PreparedStatement pstmt;
			ResultSet rs;
			System.out.println("DBConn : 데이터베이스 연결성공");
			return conn;
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("DBConn : 데이터베이스 연결실패");
			System.out.println("DBConn : Message : " + e.getMessage());
		}
		return null;
	}

	public static void close(Connection conn, PreparedStatement pstmt) {
		try {
			conn.close();
			pstmt.close();
		} catch (Exception e) {
			System.out.println("DB종료시 오류가 발생 : " + e.getMessage());
		}
	}

	public static void close(Connection conn, PreparedStatement pstmt, ResultSet rs) {
		try {
			conn.close();
			pstmt.close();
			rs.close();
		} catch (Exception e) {
			System.out.println("DB종료시 오류가 발생 : " + e.getMessage());
		}
	}

}

 

 

Player.java

더보기
package com.jaybon.baseball.model;

import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Player {
	
	int id;
	int playerNum;
	String playerName;
	String position;
	String teamName;

}

 

 

Team.java

더보기
package com.jaybon.baseball.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Team {
	
	int id;
	String teamName;
	
}

 

 

TeamRepository.java

더보기
package com.jaybon.baseball.repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jaybon.baseball.db.DBConn;
import com.jaybon.baseball.model.Team;

public class TeamRepository {
	private static final String TAG = "TeamListRepository : "; // TAG 생성 (오류 발견시 용이)
	private static TeamRepository instance = new TeamRepository();

	private TeamRepository() {
	}

	public static TeamRepository getInstance() {
		return instance;
	}

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	
	public List<Team> findAll() { // object 받기(안에 내용 다 받아야 하니까)
		final String SQL = "SELECT id, teamname FROM teamlist ORDER BY id asc";
		
		List<Team> teamList = null;
		try {
			conn = DBConn.getConnection(); // DB에 연결
			pstmt = conn.prepareStatement(SQL);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				teamList = new ArrayList<>();
				
				Team team = Team.builder()
						.id(rs.getInt(1))
						.teamName(rs.getString(2))
						.build();
				
				teamList.add(team);
				
				while (rs.next()) {
					
					Team team1 = Team.builder()
							.id(rs.getInt(1))
							.teamName(rs.getString(2))
							.build();
					
					teamList.add(team1);
					
				}
			}
			return teamList;
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println(TAG + "findAll : " + e.getMessage());
		} finally {
			DBConn.close(conn, pstmt, rs);
		}
		return null; // 실패시
	}
}

 

 

PlayerRepository.java

더보기
package com.jaybon.baseball.repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jaybon.baseball.db.DBConn;
import com.jaybon.baseball.model.Player;

public class PlayerRepository {
	private static final String TAG = "PlayerListRepository : "; // TAG 생성 (오류 발견시 용이)
	private static PlayerRepository instance = new PlayerRepository();

	private PlayerRepository() {
	}

	public static PlayerRepository getInstance() {
		return instance;
	}

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	public List<Player> findPlayerNumNameFromTeam(String teamName) { // object 받기(안에 내용 다 받아야 하니까)
		final String SQL = "SELECT playernum, playername  FROM playerlist WHERE teamname like ? ORDER BY playernum asc";
		
		List<Player> playerList = null;
		try {
			conn = DBConn.getConnection(); // DB에 연결
			pstmt = conn.prepareStatement(SQL);
			pstmt.setString(1, teamName);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				playerList = new ArrayList<>();
				
				Player player = Player.builder()
						.playerNum(rs.getInt(1))
						.playerName(rs.getString(2))
						.build();
				
				playerList.add(player);
				
				while (rs.next()) {
					
					Player player1 = Player.builder()
							.playerNum(rs.getInt(1))
							.playerName(rs.getString(2))
							.build();
					
					playerList.add(player1);
					
				}
			}
			return playerList;
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println(TAG + "findPlayerNumNameFromTeam : " + e.getMessage());
		} finally {
			DBConn.close(conn, pstmt, rs);
		}
		return null; // 실패시
	}
	
	public Player findPlayerDesc(String teamName, int playerNum) { // object 받기(안에 내용 다 받아야 하니까)
		final String SQL = "SELECT playernum, playername, position  FROM playerlist WHERE teamname like ? and playernum = ?";
		
		Player player = null;
		try {
			conn = DBConn.getConnection(); // DB에 연결
			pstmt = conn.prepareStatement(SQL);
			pstmt.setString(1, teamName);
			pstmt.setInt(2, playerNum);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				player = Player.builder()
						.playerNum(rs.getInt(1))
						.playerName(rs.getString(2))
						.position(rs.getString(3))
						.build();
			}
			return player;
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println(TAG + "findDesc : " + e.getMessage());
		} finally {
			DBConn.close(conn, pstmt, rs);
		}
		return null; // 실패시
	}
}

 

 

Action.java

더보기
package com.jaybon.baseball.action;

import java.io.IOException;

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

public interface Action {
	public void execute(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException;
}

 

 

TeamHomeAction.java

더보기
package com.jaybon.baseball.action.team;

import java.io.IOException;
import java.util.List;

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

import com.google.gson.Gson;
import com.jaybon.baseball.action.Action;
import com.jaybon.baseball.model.Team;
import com.jaybon.baseball.repository.TeamRepository;

public class TeamHomeAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		TeamRepository teamRepository = TeamRepository.getInstance();
		
		List<Team> teamList = teamRepository.findAll();
		
		request.setAttribute("teamList", teamList);
		
		RequestDispatcher rd = request.getRequestDispatcher("home.jsp");
		rd.forward(request, response);
		
	}
	
}

 

 

PlayerGetPlayerAction.java

더보기
package com.jaybon.baseball.action.player;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

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

import com.google.gson.Gson;
import com.jaybon.baseball.action.Action;
import com.jaybon.baseball.model.Player;
import com.jaybon.baseball.repository.PlayerRepository;

public class PlayerGetPlayerAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String teamName = request.getParameter("teamName");
		
		PlayerRepository playerRepository = PlayerRepository.getInstance();
		
		List<Player> playerList = playerRepository.findPlayerNumNameFromTeam(teamName);
		
		Gson gson = new Gson();
		
		String playerListJson = gson.toJson(playerList);
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter pw = response.getWriter();
		
		pw.println(playerListJson);
		
	}

}

 

 

PlayerGetDescAction.java

더보기
package com.jaybon.baseball.action.player;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

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

import com.google.gson.Gson;
import com.jaybon.baseball.action.Action;
import com.jaybon.baseball.model.Player;
import com.jaybon.baseball.repository.PlayerRepository;

public class PlayerGetDescAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String teamName = request.getParameter("teamName");
		int playerNum = Integer.parseInt(request.getParameter("playerNum"));
		
		
		PlayerRepository playerRepository = PlayerRepository.getInstance();
		
		Player player = playerRepository.findPlayerDesc(teamName, playerNum);
		
		Gson gson = new Gson();
		
		String playerJson = gson.toJson(player);
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter pw = response.getWriter();
		
		pw.println(playerJson);
		
	}

}

 

 

TeamController.java

더보기
package com.jaybon.baseball.controller;

import java.io.IOException;

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

import com.jaybon.baseball.action.Action;
import com.jaybon.baseball.action.team.TeamHomeAction;



// http://localhost:8000/blog/user
@WebServlet("/team")
public class TeamController extends HttpServlet {
	private final static String TAG = "BaseballController : ";
	private static final long serialVersionUID = 1L;

	public TeamController() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doProcess(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// http://localhost:8000/product/user?cmd=test
		String cmd = request.getParameter("cmd");
		System.out.println(TAG + "router : " + cmd);
		Action action = router(cmd);
		action.execute(request, response);
	}

	public Action router(String cmd) {
		if (cmd.equals("home")) {
			return new TeamHomeAction();
		} 
		return null;
	}
}

 

 

PlayerController.java

더보기
package com.jaybon.baseball.controller;

import java.io.IOException;

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

import com.jaybon.baseball.action.Action;
import com.jaybon.baseball.action.player.PlayerGetDescAction;
import com.jaybon.baseball.action.player.PlayerGetPlayerAction;



// http://localhost:8000/blog/user
@WebServlet("/player")
public class PlayerController extends HttpServlet {
	private final static String TAG = "PlayerController : ";
	private static final long serialVersionUID = 1L;

	public PlayerController() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doProcess(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// http://localhost:8000/product/user?cmd=test
		String cmd = request.getParameter("cmd");
		System.out.println(TAG + "router : " + cmd);
		Action action = router(cmd);
		action.execute(request, response);
	}

	public Action router(String cmd) {
		if (cmd.equals("getPlayer")) {
			return new PlayerGetPlayerAction();
		} else if (cmd.equals("getDesc")) {
			return new PlayerGetDescAction();
		} 
		return null;
	}
}

 

 

결과

 

 

 

 

 

 

 

 

 

 

'낙서장' 카테고리의 다른 글

코딩 오류 케어  (0) 2020.06.17
200617  (0) 2020.06.17
vsCode 저장시 자동으로 코드정렬  (0) 2020.06.15
공부할거  (0) 2020.06.13
vsCode 저장시 자동 정렬되게 하기  (0) 2020.06.13

+ Recent posts