main.jsp

//style에 wrapper id와 box, inside class를 선언한다

//box-shadow를 통해 테두리를 만든다

//head부분에 meta tag를 추가한다

//body 부분에 design할 요소를 추가한다

//#first : menu part

//#ad : advertisement img

//#icon : sns icon part

//#second, third, fourth, fifth, sixth : main contents

//link를 통해 responsive.css를 가져온다

responsive.css

//pc, tablet, mobile 3가지 device에 대한 design설정

//mobile에서 second box가 사라지게 설정

result(mobile, tablet, pc)

'project(website)' 카테고리의 다른 글

First - register form  (0) 2019.08.17
First - Layout setting  (0) 2019.08.16
First - login form design  (0) 2019.08.16
First - menu part  (0) 2019.08.16
First - sns icon  (0) 2019.08.16

자바 빈은 data를 저장하기위한 필드와

data를 control하기위한 getter/setter method를

하나의 쌍으로 가지고있는 class이다

 

빈(bean)에는 DAO, DTO가 있다

DAO(Data Access Object) : DB data접근을 목적으로하는 객체이다

DTO(Data Transfer Object) : DB에 있는 record를 객체화한 class이다

DTO는 data가 포함된 객체를 다른 시스템으로 전달하는 역할을 하는객체이다

 

1. package 선언

ex) com.test.Ex.className

2. field 선언

private String name; //이름을 저장할 filed 선언

private STring userid; // ID를 저장할 field 선언

2.5. 생성자 생성

3. getter/setter method 정의 (property 선언)

property: private field를 외부에서 접근하기위해서 

공개형 접근제어자 public 으로 method를 정의해 놓고

이를통해 간접적으로 field에 접근하는 방식

 

자바빈과 관련된 action tag

<jsp:useBean> : 자바빈을 생성

ex) <jsp:useBean class = "class full name" id = "bean name" [scope="range"] />

<jsp:getProperty> : 자바빈에서 정보를 얻어온다

ex) <jsp:getProperty name="bean name" property="property name"/>

<jsp:setProperty> : 자바빈에 정보를 저장한다

ex) <jsp:setProperty name="bean name" property="property name" value="값"/>

-----

package com.test.ex;

 

public class Person{

private String name;

private int id;

 

public Person(){

}

 

public String getName(){

return name;

}

public String setName(String name){

this.name = name;

}

 

public int getId(){

return id;

}

public int setId(int id){

this.id = id;

}

}

-------

<jsp:useBean id="Person" class="com.test.ex.Person" scope="page"/>

<jsp:setProperty name="Person" property="name" value = "jusung"/>

<jsp:setProperty name="Person" property="id" value = "1234"/>

<jsp:getProperty name="Person" property="name"/>

<jsp:getProperty name="Person" property="id"/>

 

[자바빈의 영역(Scope)]

-page(default) : 현재 page 범위에만 한정, 페이지 처리가 끝나면 유효하지 않는다.

- request : request의 생명주기는 요청을 받고 요청처리를 완료하는 시점이다.

따라서 빈의 Scope는 request의 생명주기와 같다. 

-session : 세션의 생명주기는 설정된 유효시간이다. 따라서 빈의 스코프는 세션의 유효시간동안이다

-application : 웹사이트가 실행되는 동안 빈의 스코프이다

 

page이동 관련 method

1. forward action : page를 이동시킨다

이동후 페이지와 이동 전의 페이지는 request를 공유한다

2. response.sendRedirect="aa.jsp";

forward 방식과 달리 새로운 request를 발생시킨다

새로운 요청을 발생시키기 때문에 page이동후 로직을 계속 수행한다

3. 자바 스크립트의 location.href="aaaa.jsp";

지정된 url로 이동시킨다

href이후로도 계속 로직을 수행한다

sendRedirect()와 비슷하다

return값을 줘서 로직을 수행하지 않게할수있다

 

 

 

 

 

 

 

'JSP' 카테고리의 다른 글

예외처리(error page)  (0) 2019.08.14
session  (0) 2019.08.14
쿠키(cookie)  (0) 2019.08.14
request, response, action tag  (0) 2019.08.14
JSP tag 종류, page, include, taglib 지시자, jsp 내부객체  (0) 2019.08.14

예외발생시 서버에서 제공하는 예외 페이지가 나오게되는데

이러한 예외페이지를 디자인된 페이지로 유도하는 과정을 예외처리라한다

 

<%@ page errorPage="error.jsp" %>

//에러 발생시 errorPage로 넘기겠다는 의미이다

erro.jsp

<%@page isErrorPage="true"%>

<%page isErrorPage = "true"%>

<% response.setStatus(200); %>

//서버 상태 code를 200으로 setting한다

<%= exception.getClass().getName() %>

<%= exception.getMessage() %>

HTTP 에러코드

100 : continue

200 : Ok. 에러없이 전송성공

307 : 임시로 페이지가 redirect 됨

400 : 접근을 허용하지 않는다

404 : 요청한 페이지가 없을때(URL이 존재하지 않음)

405 : 요청된 method가 허용되지 않을때

500 : 서버 내부의 에러(JSP에서 예외가 발생하는경우)

503 : 서버 과부하이거나 서버 유지보수차원에서 일시적으로 중지시킨경우 

---web.xml에서 설정하는경우

<error-page>

<error-code>404</error-code>

<location>/404error.jsp</location>

</error-page>

<error-page>

<error-code>500</error-code>

<location>/500error.jsp</location>

</error-page>

errorpage에 <% response.setStatus(200); %> 추가해주고

body에 내용을 쓰면된다

'JSP' 카테고리의 다른 글

자바 빈(bean), scope,(DAO, DTO)  (0) 2019.08.15
session  (0) 2019.08.14
쿠키(cookie)  (0) 2019.08.14
request, response, action tag  (0) 2019.08.14
JSP tag 종류, page, include, taglib 지시자, jsp 내부객체  (0) 2019.08.14

session은 서버와의 connection 관계를 유지하기 위해 이용자 정보를 저장하는 객체이다

세션은 서버에서만 접근이 가능해 보안성이 뛰어나고 data에대한 제한이없다

 

relative method

-setAttribute(): 세션의 속성 설정

session.setAttribute("id", "test");

-getAttribute(): 세션에서 data를 얻거나 사용할때

String id =(String)ssesion.getAttribute("id");

-getAttributeName(): 세션에 저장되어있는 모든 data의 이름을 얻어올때

-removeAttribute(): 세셔에서 특정 data를 제거한다

session.removeAttribute("id");

-invalidate(): 세션의 모든 데이터를 삭제한다

session.invalidate();

getId(): 자동 생성된 session ID를 얻어올때 사용한다.

isNew(): 세션이 최초로 생성되었는지 여부를 알고자 할때

getMaxInactiveInterval(): 세션의 유효시간을 얻어올때 

---입력된값을 id, pw에 받아와 세션을설정한다

<%

String id = request.getParameter("id");

String pw = request.getParameter("pw");

 

session.setAttribute("id", id);

session.setAttribute("password", pw);

%>

---설정된 세션을 가져온다(object로 반환된다)

<%

Object idObj = session.getAttribute("id");

String id = (String)idObj;

 

Object pwObj = session.getAttribute("password")

String pw = (String)pwObj;

%>

---invalidate() 세션지우기

<%

session.invalidate();

%>

'JSP' 카테고리의 다른 글

자바 빈(bean), scope,(DAO, DTO)  (0) 2019.08.15
예외처리(error page)  (0) 2019.08.14
쿠키(cookie)  (0) 2019.08.14
request, response, action tag  (0) 2019.08.14
JSP tag 종류, page, include, taglib 지시자, jsp 내부객체  (0) 2019.08.14

쿠키란 사용자가 웹사이트를 처음 방문할때 server에 생성되

client의 pc에 저장되는 4KB의 작은 파일이다

 

cookie 생성은 cookie class를 사용하고 setter를 이용해 쿠키 속성을 설정한다

addCookie()를 이용해 response객체에 저장후 쿠키를 전송한다

 

쿠키 관련 method

setMaxAge(): 쿠키 유효기간을 설정

setPath(): 쿠키사용을 위한 directory를 설정(특정 경로명을 갖는 URL로 전송하도록 설정)

setValue(): 쿠키값을 설정

setVersion(): 쿠키의 버전을 설정

getMaxAge(): 쿠키의 유효기간 정보를 얻어온다

getName(): 쿠키의 이름을 얻어온다

getPath(): 쿠키의 유효 디렉토리 정보를 얻어온다

getVersion(): 큐키의 버전을 얻어온다

getCookies(): 쿠키 데이터를 읽어올때 사용한다

 

저장된 쿠키 사용 순서

1. 웹브라우저의 요청에서 쿠키를 얻어온다

2. 쿠키는 이름, 값의 쌍으로된 배열형태로 return 된다

3. return된 쿠키의 배열에서 쿠키의 이름을 가져온다

4. 쿠키의 이름을 통해서 해당 쿠키의 설정된 값을 추출한다

---쿠키생성

<%

String cookieName = "id";

Cookie cookie = new Cookie(cookieName, "test");

cookie.setMaxAge(60*30);

response.addCookie(cookie);

%>

---생성된 쿠키확인

<%

Cookie[] cookies = request.getCookies();

if(cookies != null){

for(int i=0; i<cookies.length; i++){

String str = cookies[i].getName();

if(str.equals("id")){

out.println(i+cookies[i].getName());

out.println(i+cookies[i].betValue());

}}}

%>

---쿠키삭제

<%

Cookie[] cookies = request.getCookies();

for(int i=0, i<cookies.length; i++){

String str = cookies[i].getName();

if(str.equals("id")){

out.println(cookies[i].getName());

cookies[i].setMaxAge(0);

response.addCookie(cookies[i]);

}}

%>

---삭제된 쿠키확인

<%

Cookie[] cookies = request.getCookies();

if(cookies != null){

for(int i=0; i<cookies.length; i++){

out.println(cookies[i].getName());

out.println(cookies[i].getName());

}}

%>

'JSP' 카테고리의 다른 글

예외처리(error page)  (0) 2019.08.14
session  (0) 2019.08.14
request, response, action tag  (0) 2019.08.14
JSP tag 종류, page, include, taglib 지시자, jsp 내부객체  (0) 2019.08.14
register and database list  (0) 2019.08.09

request 객체: 사용자(client)의 요청을 관리하는 객체

--relative method

getContextPath(): web application의 context path를 얻어올때 사용하는 method

getMethod(): get방식과 post방식을 구분하기위해 사용하는 method

getProtocol(): 해당 protocol을 얻어올때 사용하는 method

getRequestURL(): 요청한 URL을 얻어올때 사용하는 method

getRequestURI(): 요청한 URI를 얻어올때 사용하는 method

getQueryString(): 쿼리 스트링을 얻어온다

 

request parameter method

getParameter(String name) : name에 해당하는 parameter의 값을 구할때 사용

getParameterNames() : 모든 parameter의 이름을 얻어올때 사용한다.

getParameterValues(String name) : name에 해당하는 parameter의 값들을 배열 type으로 얻어올수있다

----------

response 객체 method

getCharacterEncoding(): 응답할때 문자 인코딩을 얻어올때

addCookie(cookie): 쿠키를 지정할때

sendRedirect(URL): 이동하고자 하는 URL을 지정할때 

------

action tag란 page내에서 어떤 동작을 하도록 지시하는 tag를 말한다

페이지이동(forward), include, param

param을 이용해 data를 이동이동시키고 request.getParameter()로 data를 받는다

<jsp:forward param="aaa.jsp">

<jsp:param value"hahaha" name="lauging"/>

</jsp:forward>

 

표준 액션(standard action): jsp page에서 바로 사용할수있는 action

<jsp:include page="a.jsp"> // jsp 접두어는 표준 액션을 의미한다

커스텀 액션(custom action): 별도의 라이브러리를 설치해서 사용하는 action

<c: set var="i" value="0"/> //

 

 

 

 

'JSP' 카테고리의 다른 글

session  (0) 2019.08.14
쿠키(cookie)  (0) 2019.08.14
JSP tag 종류, page, include, taglib 지시자, jsp 내부객체  (0) 2019.08.14
register and database list  (0) 2019.08.09
DB연동(oracle DB, Eclipse)  (0) 2019.08.08

director: <%@ %> : page속성
지시자의 3가지 종류
page 지시자
- info 속성: page를 설명하는 문자열 <%@ page info = "copyrights by ~" %>
- language 속성: jsp page에서 사용할 언어를 지정 <%@ page language="java" %>
- contentType 속성: jsp page의 내용을 어떠한 형태로 출력할 지를 브라우저에 알려주는 역할 (charset=euc-kr 포함)
- extends 속성: jsp가 서블릿으로 변환될때 상속받을 class를 지정하는 속성
- import 속성: 다른 package에 있는 class를 가져다 사용할때 쓴다. <%@ page import="java.utill.*, java.sql.*" %>
- session 속성: HttpSession 속성의 사용 여부를 지정 <%@ page session = "false" %>
- buffer 속성: JSP page의 출력 크리를 KB단위로 지정하는 속성, 기본값은 8KB
- autoFlush 속성: 기본값은 true이고, 버퍼가 다 찼을 경우 자동적으로 버퍼를 비우는 속성
- isThreadSafe: 여러개의 요청을 처리할지 여부를 결정
- erroPage 속성: 예외처리를 할 페이지를 지정
- isErrorPage: error page를 담당하는 page인지 여부를 지정하는 속성
- pageEncoding : contentType의 charset과 같다 

include 지시자: 현재 JSP page에 다른 JSP page나 html문서를
file 형태로 불러와 현재 page의 일부로 사용할때사용하는 속성이다
<%@include file="aaa.jsp"%>
taglib 지시자: action을 사용할때 필요한 지시자
<%@ taglib prefix="c" uri = "http://oracle.com/jsp/jstl/core"%>

스클립트릿: <% %> : java code
익스프레션: <%= %> : 결과값 출력
선언 : <%! %> : variable, method선언

주석 : <%-- --%>
action tag:   : 자바빈 연결

JSP의 내부 객체
내부객체란 객체를 생성하지 않고 바로 사용할수있는 객체를 의미한다
입출력 객체: request, response, out
서블릿 객체: page, config
세션 객체: session
예외 객체: exception

'JSP' 카테고리의 다른 글

쿠키(cookie)  (0) 2019.08.14
request, response, action tag  (0) 2019.08.14
register and database list  (0) 2019.08.09
DB연동(oracle DB, Eclipse)  (0) 2019.08.08
JSP register, log in, modify, logout process.  (0) 2019.08.02

Activity life Cycle 은 activity의 상태정보(running, pause, stop)이 바뀌는것을 말한다

실행(running): activity가 화면에 보이면서 실행되어있는 상태로 focus가 있는상태이다

일시정지(pause): 사용자에게는 보이지만 focus를 잃은 상태이다(대화상자가 일부가리고있는경우)

중지(stop): 다른 activity에 의해 완전히 가려진 상태

 

System에서 Activity에 대한 상태정보를 관리하며 그에따른 필요한 method를 자동으로 호출한다

onCreate()

a. memory에 activity가 처음 생성될때

b. activity안에 view들을 설정할때

c. Bundle객체를 이용해 이전상태를 복원할때

d. 다음에는 onStart()가 호출된다

onStart()

a. activity가 화면에 보이기 직전에 호출

b. activity가 화면에 보이면 다음에 onResume()을 호출

c. activity가 화면에서 가려지면 다음에 onStop()호출

onResume()

a. 사용자와 상호작용하기 직전에 호출

onRestart()

a. activity가 중지된 이후에 다시 실행될때 호출

b. 다음에는 onStart()가 호출

onPause()

a. 다른 activity가 실행될때 호출된다

b. 저장되지 않은 data를 저장하는 역할

c. 이상태에서는 activity를 강제종료할수있다

onStop()

a. 더이상 화면에 보이지 않을때 호출

b. 다른 activity가 화면을 가릴때 호출

c. 이상태에서는 system에서 강제종료 가능하다

onDestroy()

a. activity가 없어지기 전에 호출

b. finish()호출되거나, system이 강제종료시키는경우 호출

 

memory에 activity가 생성되었을때 system에서 자동으로 onCreate(), onStart()를 호출

실행후 일시정지될때 onPause()가 호출된다. 일시정지후 다시 실행될때 onResume()이 실행된다.

onPause()는 일시정지나 중지상태로 변할때 호출된다. 

일시정지에서 중지상태로 갈때는 onStop()가 호출된다

중지에서 다시 실행상태로 갈때 onRestart(), onStart(), onResume()이 실행된다

소멸될때에는 onDestroy()가 호출된다.

 

activity_main.xml

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click the below button"
android:textSize="20sp"
tools:layout_editor_absoluteX="106dp"
tools:layout_editor_absoluteY="170dp" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new activity"
android:textSize="20sp"
tools:layout_editor_absoluteX="126dp"
tools:layout_editor_absoluteY="233dp"/>

activity_new.xml

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new Activity"
android:textSize="30sp"
tools:layout_editor_absoluteX="125dp"
tools:layout_editor_absoluteY="262dp" />

NewActivity.java

public class NewActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);

output("onCreate() call");
}
protected void onStart(){
super.onStart();
output("onStart() call");
}
protected void onRestart(){
super.onRestart();
output("onRestart() call");
}
protected void onResume(){
super.onResume();
output("onResume() call");
}
protected void onPause(){
super.onPause();
output("onPause() call");
}
protected void onStop(){
super.onStop();
output("onStop() call");
}
protected void onDestroy(){
super.onDestroy();
output("onDestroy() call");
}
public void output(String msg){
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
Log.d("new", msg);
}
}

MainAtivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button button = findViewById(R.id.btn1);

button.setOnClickListener(listener);
}
View.OnClickListener listener = new View.OnClickListener(){
public void onClick(View view){
//명시적(Explicit) intent
Intent intent = new Intent(getApplicationContext(), NewActivity.class);
startActivity(intent);
}
};
}

 

 

'android studio' 카테고리의 다른 글

android register db connection using JSP  (0) 2019.09.06
android internet check  (0) 2019.09.05
intent  (0) 2019.08.14
startActivityForResult()(화면전환)  (0) 2019.08.13
activity 추가하기  (0) 2019.08.13

+ Recent posts