What job do you want? Quitting and Recruiting

Sudden thought

Reading this post might mean you are thinking of quitting your job or trying to get another job.

Because I have same thinking with you, while having many thoughts, I write some thoughts down for sharing.


What is job?

Maybe jobs mean people buy my effort so we can earn money as a result.

But the effort should be something I feel good or I feel interested or I feel it is rewarding.

However, my present effort getting paid is not like that.

The reasons why I want to quit my job or move to another one but I feel it is hard are like these.

  1. I feel I develop myself,
  2. I feel it is rewarding,
  3. I feel interested. That is the 1st reason,

2nd, I am getting well paid for my effort now because it is big company as more than I have actually,

3rd, I don’t know what people will look at my effort worthy. Shortly, I don’t know if I can MOVE to another company. And maybe I can’t because I don’t have enough skills.

I get those thoughts

Personally, I want to do something I can do after retirement. Or I want to do something there is no retirement. And by having my own contents, I want to be the person whom people can’t replace me with anyone.

For those, one way to do it is being full stack developer. When I get an idea, I wan to plan the project and make the project from A to Z. But unless I make my own business or work in startup, there are really few jobs I can do both. And then, I will meet the same frustrations I saw between planners and programmers again. And when I saw it in startup and when I see it in a big company now, it is pretty hard to solve. so.. is it right?…

What if I get a job which I can actually have my own contents?

For examples, writer writing own literature, creators making videos or diorama makers based on hand skills? It sounds nice but I don’t know if I can do now.

By thinking of ‘I want to get my own contents’, I could think of this much.


I support all the people reading my post this much and I hope all you guys will arrange thoughts and I hope by the arranging you guys will get better job which gives enough rewarding or get own business.

Comments

Java bean

Java bean

  • 반복적인 작업을 효율적으로 하기 위해 사용
  • Java의 데이터(속성)와 기능(메소드)으로 이루어진 클래스
  • JSP페이지를 만들고, 액션태그를 이용해서 빈 사용, 내부 데이터 처리

빈 관련 액션 태그(useBean, setProperty,getProperty)

  • 액션 태그 중에서 bean과 관련한 태그들
  • 주로 데이터 업데이트하고 얻어오는 역할

useBean

  • 특정 bean을 사용한다고 명시할 때 사용
    1
    2
    3
    <jsp:useBean id="student" class="com.javalec.ex.Student" scope="page" />

    // <jsp:useBean id="빈 이름" class="클래스 이름" scope="스코프 범위" />
  • scope
    • page : 생성된 페이지 내에서만 사용 가능
    • request : 요청된 페이지 내에서만 사용 가능
    • session : 웹브라우저의 생명주기와 동일하게 사용 가능
    • application : 웹애플리케이션의 생명주기와 동일하게 사용 가능

setProperty

  • 데이터 값을 설정할 때 사용
    1
    2
    <jsp:setProperty name="student" property="name" value="홍길동" />
    // <jsp:setProperty name="빈 이름" property="속성이름" value="속성(데이터)값" />

getProperty

  • 데이터 값을 가져올 때 사용
    1
    2
    <jsp:getProperty name="student" property="name />
    // <jsp:setProperty name="빈 이름" property="속성이름" />
Comments

Exception

Exception

  1. 페이지 지시자 이용

    • 예외 발생

      1
      2
      3
      4
      5
      <%@ page errorPage="errorPage.jsp"%>

      <%
      int i = 40/0;
      %?
    • 예외 페이지

      1
      2
      3
      4
      5
      6
      //반드시 true로 명시해야함
      //명시해야 exception객체 사용가능
      <%@ page isErrorPage="true"%>
      <% response.setStatus(200); %>

      <%= exception.getMessage() %>

  2. Web.xml파일 이용

1
2
3
4
5
6
7
8
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error500.jsp</location>
</error-page>
Comments

Session

Session

  • Cookie처럼 웹브라우저와의 관계를 유지하기 위한 수단
  • 서버상의 객체로 존재 Cf)Cookie는 클라이언트의 특정 위치에 저장
  • 따라서 Session은 서버에서만 접근 가능하여 보안이 좋고, 저장할 수 있는 데이터의 한계가 없음
  1. 클라이언트 요청 - 웹브라우저
  2. Session 자동 생성
  3. Session 속성 설정 - session내부 객체의 메소드 이용
  • 각 브라우저마다 세션 생성됨

Session 관련 메소드

1
2
3
4
5
6
7
8
setAttribute() - 세션에 데이터 저장
getAttribute() - 세션에서 데이터 획득
getAttributeNames() - 세셔넹 저장되어 있는 모든 데이터의 이름(유니크한 키값)을 획득
getId() - 자동 생성된 세션의 유니크한 아이디 획득
isNew() - 세션이 최초 생성되었는지, 이전에 생성된 세션인지 구분
getMaxInactiveInterval() - 세션의 유효시간 획득, 가장 최근 요청시점을 기준으로 카운트
removeAttribute() - 세션에서 특정 데이터 제거
inValidate() - 세션의 모든 데이터를 삭제

Example

  • sessionInit.jsp

    1
    2
    3
    4
    5
    6
    <%
    session.setAttribute("mySessionName","mySessionData");
    sessoin.setAttribute("myNum",12345);
    %>

    <a href="sessionGet.jsp">session get</a>
  • sessoinGet.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <%
    Object obj1 = session.getAttribute("mySessionName"); // 이때 반환 값은 무조건 Object형임***
    String mySessionName = (String)obj1;
    out.println(mySessionName + "<br/>");

    Object obj2 = session.getAttribute("myNum");
    Integer myNum = (Integer)obj2;
    out.println(myNum + "<br/>");

    out.println("****************************** <br/>");

    String sName;
    String sValue;
    Enumeration enumeration = session.getAttributeNames(); // 모든 세션 값들 가져옴
    while(enumeration.hasMoreElements()){
    sName = enumeration.nextElement().toString();
    sValue = session.getAttribute(sName).toString();

    out.println("sName: " + sName + "<br/>");
    out.println("sValue: " + sValue + "<br/>");
    }

    out.println("****************************** <br/>");

    String sessionId = session.getId(); //세션 아이디 획득
    out.pringln("sessionId: " + sessionId);
    int sessionInter = session.getMaxInactiveInterval();
    out.pringln("sessionInter: " + sessionInter);

    out.println("****************************** <br/>");

    session.removeAttribute("mySessionData"); //특정 데이터를 삭제
    Enumeration enumeration1 = session.getAttributeNames();
    while(enumeration1.hasMoreElements()){
    sName = enumeration1.nextElement().toString();
    sValue = session.getAttribute(sName).toString();

    out.println("sName: " + sName + "<br/>");
    out.println("sValue: " + sValue + "<br/>");
    }

    out.println("****************************** <br/>");

    session.inValidate(); //세션 자체를 삭제
    if(request.isRequestedSessionIdValid()){
    out.println("session valid");
    } else {
    out.println("session invalid");
    }
    %>
Comments

Cookie

Cookie

  • http프로토콜은 웹브라우저에게 응답 후 연결을 끊음
  • cookie연결이 끊겼을 때 어떤 정보를 지속적으로 유지하기 위한 수단
  • 서버에 생성하여 서버가 아닌 클라이언트측에 특정 정보를 저장함
  • 서버에 요청할 때 마다 쿠키의 속성값을 참조, 변경 할 수 있음
  • 4kb로 용량이 제한적이며, 300개까지 데이터 정보를 가질 수 있음

Grammar

  1. 쿠키 생성 - 쿠키 클래스 이용
  2. 속성 설정 - setter이용
  3. response객체에 쿠키 탑재 - response.addCookie() 이용

Method

1
2
3
4
5
6
7
8
9
10
setMaxAge() - 쿠키 유효시간 설정
setPath() - 쿠키사용의 유효 디렉토리 설정
setValue() - 쿠키의 값을 설정
setVersion() - 쿠키 버전 설정

getMaxAge() - 쿠키 유효기간 정보 획득
getName() - 쿠키 이름 획득
getPath() - 쿠키사용의 유효 디렉토리 정보 획득
getValue() - 쿠키의 값 획득
getVersion() - 쿠키 버전 정보 획득

Example

  • cookieSet.jsp

    1
    2
    3
    4
    5
    6
    7
    8

    <%
    Cookie cookie = new Cookie("cookieName","cookieValue");
    cookie.setMaxAge(60*60); //1시간
    response.addCookie(cookie);
    %>

    <a href = "cookieGet.jsp">cookie get</a>
  • cookieGet.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <%
    Cookie[] cookies = request.getCookies(); //쿠키 전부 배열로 가져옴

    for(int i=0; i<cookies.length;i++){
    // 각 쿠키를 돌면서 정보 확인
    String str = cookies[i].getName();
    if(str.equals("cookieName")){
    out.println("cookies["+i+"] name: " + cookies[i].getName() + "<br/>");
    out.println("cookies["+i+"] value: " + cookies[i].getValue() + "<br/>");
    out.println("===================<br/>")
    }
    }
    %>

    <a href="cookieDel.jsp">cookie delete</a>
  • cookieDel.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <%
    Cookie[] cookies = request.getCookies();

    for(int i=0; i<cookies.length;i++){
    String str = cookies[i].getName();
    if(str.equals("cookieName")){
    out.println("cookies["+i+"] name: " + cookies[i].getName() + "<br/>");
    out.println("cookies["+i+"] value: " + cookies[i].getValue() + "<br/>");

    cookies[i].setMaxAge(0); // 유효시간 0초로 해서 삭제
    response.addCookie(cookies[i]); // 속성 변경 후 다시 탑재해서 이어나감
    }
    }
    %>

    <a href="cookieTest.jsp">cookie Test</a>
  • cookieTest.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <%
    Cookie[] cookies = request.getCookies();

    if(cookies != null){
    for(int i=0; i<cookies.length;i++){
    out.println("cookies["+i+"] name: " + cookies[i].getName() + "<br/>");
    out.println("cookies["+i+"] value: " + cookies[i].getValue() + "<br/>");
    }
    }
    %>

속성 변경시 response객체에 꼭 다시 넣어줘야함

Comments

JSP action tag

Action tag

  • jsp페이지에서 어떤 동작을 하도록 지시하는 태그
  • forward, include, param Tag

forward Tag

  • 다른 특정 페이지로 전환할 때

    1
    2
    3
    <h1>main.jsp페이지 입니다.</h1>

    <jsp:forward page="sub.jsp" />

    main.jsp는 잠깐 스쳐 지나가고 sub.jsp가 보임


include tag

  • 현재 페이지에 다른 페이지 삽입할 때
    1
    2
    3
    <h1>include1.jsp페이지 입니다.</h1>
    <jsp:include page="include2.jsp" flush="true" />
    <h1> 다시 include1.jsp페이지 입니다 </h1>

param Tag

  • forward, include 태그에 데이터 전달을 목적으로 사용
  • 이름과 값으로 구성
    1
    2
    3
    4
    <jsp:forward page="forward_param.jsp" />
    <jsp:param name="id" value="abcde"/>
    <jsp:param name="pw" value="1234"/>
    </jsp:forward>
Comments

JSP request, response object

request

  • 웹브라우저를 통해 서버에 어떤 정보를 요청하는 것을 request라고 함
  • 이러한 요청 정보는 request객체가 관리

    • Request 객체 관련 메소드

      1
      2
      3
      4
      5
      6
      7
      getContextPath(): 웹애플리케이션의 컨텍스트 패스를 얻음
      getMethod(): get방식과 post방식을 구별할 수 있음
      getSession(): 세션 객체를 얻음
      getProtocol(): 해당 프로토콜을 얻음
      getRequestURL(): 요청 URL을 얻음
      getRequestURI(): 요청 URI를 얻음
      getQueryString(): 쿼리스트링을 얻음
    • Parameter메소드

      1
      2
      3
      getParameter(String name): name에 해당하는 파라미터 값을 구함
      getParameterNames(): 모든 파라미터 이름을 구함
      getParameterValues(String name): name에 해당하는 파라미터값을 구함 - 스트링 배열로 값 받음

response

  • 웹브라우저의 요청에 응답하는 것을 response라고 함
  • 이러한 응답의 정보를 가지고 있는 객체를 response객체라고 함
  • response객체 관련 메소드
    1
    2
    3
    getCharacterEncoding(): 응답할 때 문서의 인코딩 형태를 구함
    addCookie(Cookie): 쿠키를 지정
    sendRedirect(URL): 지정한 URL로 이동
Comments

JSP Scriptlet, declaration, expression, 지시자, comment

Scriptlet - <% java 코드 %>

  • jsp페이지에서 java언어를 사용하기 위한 요소
  • 거의 모든 java코드를 사용 가능
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <body>
    <%
    int i = 0;
    while(true){
    i++;
    out.println("2 * " + i + " = " + ( 2*i ) + "<br/>");
    %>

    ========== <br />

    <%
    if(i>=9) break;
    }
    %>
    </body>

declaration - <%! java 코드 %>

  • jsp페이지 내에서 사용되는 변수 또는 메소드를 선언할 때 사용
  • 여기서 선언된 변수 및 메소드는 전역의 의미로 사용
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <body>
    <%!
    int i = 10;
    String str = "ABCDE";
    %>
    <%!
    public int sum(int a, int b){
    return a+b;
    }
    %>

    <%
    out.println("i = " + i + "<br />");
    out.println("str = " + str + "<br />");
    out.println("sum = " + sum(1,5) + "<br />");
    %>
    </body>

expressions - <%= java 코드 %>

  • jsp페이지 내에서 사용되는 변수의 값 또는 메소드 호출 결과값을 출력하기 위해 사용
  • 결과값은 String타입이며 ;를 사용할 수 없음
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <body>
    <%!
    int i = 10;
    String str = "ABCDE";

    public int sum(int a, int b){
    return a+b;
    }
    %>

    <%= i %> <br/>
    <%= str %> <br/>
    <%= sum(1,5) %> <br/>
    </body>

지시자

  • jsp페이지의 전체적인 속성을 지정할 때 사용합니다.
  • page,include,taglib가 있으며, <%@ 속성 %>형태로 사용

    1
    2
    3
    page : 해당 페이지의 전체적인 속성 지정
    include : 별도의 페이지를 현재 페이지에 삽입
    taglib : 태그라이브러리의 태그 사용

page

  • 페이지 속성을 지정
  • 주로 사용되는 언어 지정 및 import문을 많이 사용

    1
    <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>

include

  • 현재 페이지내에 다른 페이지를 삽입할 때 사용
  • file속성을 이용

    1
    2
    3
    <h1> include.jsp페이지 입니다. </h1><br />
    <%@ include file = "include01.jsp" %>
    <h1> 다시 include.jsp 페이지 입니다. </h1><br />

comment

  • html 주석 => <!-- comments --> 소스에서 보임
  • jsp 주석 => <%-- comments --> 컴파일 이후에 출력되므로 소스에서 안보임
Comments

JSP tags, way to run, internal object

JSP tags

1
2
3
4
5
6
<%@    %> : 페이지 속성
<%-- --%> : 주석
<%! %> : 변수, 메소드 선언
<%= %> : 결과값 출력
<% %> : Java 코드
<jsp:action> <jsp:action> : 자바빈 연결

JSP’s way to run

  1. 클라이언트가 웹브라우저로 helloWorld.jsp요청하면,
    JSP컨테이너가 JSP파일을 Servlet파일(.java)로 변환 - helloWorld_jsp.java
  2. 컴파일 된 후에 클래스 파일(.class)로 변환 - helloWorld_jsp.class
  3. 클라이언트에게 html파일 형태로 응답

internal object

  • 선언하지 않고 바로 사용가능한 객체
    • 입출력 객체: request, response, out
    • 서블릿 객체: page, config
    • 세션 객체: session
    • 예외 객체: exception
Comments

ServletConfig, ServletContext, ServletContextListener

ServletConfig

  • 서블릿 초기화 파라미터
  • 특정 서블릿 생성시 필요한 초기 데이터 세팅(특정 경로 및 아이디 정보 등)
  • web.xml에 기술하고 ServletConfig클래스를 이용해서 접근(사용)함

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <servlet>
    <servlet-name>InitParam</servlet-name>
    <servlet-class>com.javalec.ex.InitParam</servlet-class>

    <init-param>
    <param-name>id</param-name>
    <param-value>abcde</param-value>
    </init-param>
    <init-param>
    <param-name>pw</param-name>
    <param-value>1234</param-value>
    </init-param>
    </servlet>

    <servlet-mapping>
    <servlet-name>InitParam</servlet-name>
    <url-pattern>/IP</url-pattern>
    </servlet-mapping>
    1
    2
    3
    4
    5
    6
    7
    8
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
    String id = getInitParameter("id");
    String pw = getInitParameter("pw");
    System.out.println("id2: " + id);
    System.out.println("pw2: " + pw);
    }
  • Servlet파일에 직접 기술하는 방법도 있음

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    @WebServlet(urlPatterns= {"/IninP"}, initParams= {@WebInitParam(name="id",value="aaaa"),@WebInitParam(name="pw",value="bbbb")})
    public class InitParam extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
    String id = getInitParameter("id");
    String pw = getInitParameter("pw");
    System.out.println("id2: " + id);
    System.out.println("pw2: " + pw);
    }
    }

ServletContext

  • 여러 Servlet에서 특정 데이터 공유
  • context parameter를 이용해서 web.xml에 데이터 기술, servlet에서 공유하면서 사용

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <context-param>
    <param-name>id</param-name>
    <param-value>abc</param-value>
    </context-param>

    <context-param>
    <param-name>pw</param-name>
    <param-value>123213</param-value>
    </context-param>
    1
    2
    3
    4
    String id = getServletContext().getInitParameter("id");
    String pw = getServletContext().getInitParameter("pw");
    System.out.println("id2: " + id);
    System.out.println("pw2: " + pw);

ServletContextListener

  • 웹애플리케이션의 생명주기 감시
  • 리스터의 해당 메소드가 웹애플리케이션으 시작과 종료시 호출됨
  • contextInitialized(), ocntextDestroyed()
  • 리스너 클래스를 따로 만들고(ServletContextListener 임플리먼트) -> web.xml에 리스너 클래스 기술

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;

    public class ServletL implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
    // TODO Auto-generated method stub
    System.out.println("contextDestroyed");
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
    // TODO Auto-generated method stub
    System.out.println("contextInitialized");
    }

    }
    1
    2
    3
    <listener>
    <listener-class>com.javalec.ex.ServletL</listener-class>
    </listener>
    • 리스너 클래스에서 어노테이션으로 명시도 가능
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      import javax.servlet.ServletContextEvent;
      import javax.servlet.ServletContextListener;
      import javax.servlet.annotation.WebListener;

      @WebListener
      public class ServletL implements ServletContextListener {

      @Override
      public void contextDestroyed(ServletContextEvent arg0) {
      // TODO Auto-generated method stub
      System.out.println("contextDestroyed");
      }

      @Override
      public void contextInitialized(ServletContextEvent arg0) {
      // TODO Auto-generated method stub
      System.out.println("contextInitialized");
      }

      }
Comments