cmd 에서 실행 ( static이라 바로가능. static이 없다면 객체생성 후 가능 )
2. 원격 프로그램 실행
잠깐,
WEB ( 웹서버 )
WAS ( 웹서버 + 웹컨테이너 ) WAS, Web Application Serve
( 단순 정적처리) 단순 html, 이미지 리소스 더빠름 html페이지 등을 네트워크망에 종속되지않고, 웹서비스를 할수 있도록 하는 어플리케이션 소프트웨어 : http요청에 따라 반응하는 프로그램 하드웨어 : 앞 선 기능을 제공하는 프로그램을 실행하는 컴퓨터
( 개발언어를 읽고 처리하여, 동적서비스 처리 ) DB연동 사용시 주로 활용 프로그램 실행환경 + DB접속기능 제공 트랜잭션 관리 비지니스로직 수행 Web Service 플랫폼 역활
※ 참고
WAS + WebServer 사용
모든 컨텐츠를 한곳에 집중시켜 웹서버와 WAS의 역할을 동시에 수행, 스위치를 통한 로드 밸러싱, 사용자가 적을 경우 효율적
WAS / WebServer 분리
서버와 WAS의 기능적 분류를 통해 효과적인 분산을 유도, 정적인 데이터는 웹서버에서 처리, 동적인 데이터는 WAS가 처리
WAS(여러개 ) / WebServer 분리
WAS단을 프리젠테이션 로직와 비즈니스 로직으로 구분하여 구성, 특정 logic의 부하에 따라 적절한 대응할 수 있지만 설계및 유지보수 단계가 복잡해 질 수가 있다.
[ 분리이유 ] WAS / WebServer
① 기능을 분리하여 서버의 부하방지 ② 물리적으로 분리하여 보안강화 ③ 다수의 WAS를 연결 가능(로드밸런싱의 역할 및 fail over, fail back 처리에 유리) ④ 여러 웹어플리케이션 서비스 가능(java서버, c#서버, php서버 등 하나의 웹서비스를 통해 서비스 가능)
2. 원격 AWS 서버PC에 올리고 실행하기
로컬프로그램
// 년월일 입력하면 요일을 알려주는 프로그램
public class YoilTeller {
public static void main(String[] args) {
// 1. 입력
String year = args[0];
String month = args[1];
String day = args[2];
int yyyy = Integer.parseInt(year);
int mm = Integer.parseInt(month);
int dd = Integer.parseInt(day);
// 2. 작업
Calendar cal = Calendar.getInstance();
cal.set(yyyy, mm - 1, dd);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
char yoil = " 일월화수목금토".charAt(dayOfWeek); // 1 = 일요일
// 3. 출력
System.out.println(year + "년 " + month + "월 " + day + "일은 ");
System.out.println(yoil + "요일입니다.");
}
}
▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
원격프로그램
// 년월일 입력하면 요일을 알려주는 프로그램
@Controller
public class YoilTeller {
@RequestMapping("/getYoil")
public void main(HttpServletRequest request, HttpServletResponse response) throws IOException {
// 1. 입력
String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");
int yyyy = Integer.parseInt(year);
int mm = Integer.parseInt(month);
int dd = Integer.parseInt(day);
// 2. 작업
Calendar cal = Calendar.getInstance();
cal.set(yyyy, mm - 1, dd);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
char yoil = " 일월화수목금토".charAt(dayOfWeek); // 1 = 일요일
// 3. 출력
response.setContentType("text/html"); // 브라우저는 응답보내주는게 text인지 binary인지 모른다.
response.setCharacterEncoding("utf-8"); // text 인코딩 형식 알려줌 (한글깨지지 않게)
PrintWriter out = response.getWriter(); //response객체에서 브라우저로 출력 스트림을 얻는다.
out.println(year + "년 " + month + "월 " + day + "일은 ");
out.println(yoil + "요일입니다.");
System.out.println(year + "년 " + month + "월 " + day + "일은 ");
System.out.println(yoil + "요일입니다.");
}
}
1. HttpServeltRequest
① 브라우저에서 URL 호출시, 톰켓이 HttpServeltRequest 객체를 만든다.
② 브라우저가 요청한 정보를 만든 HttpServeltRequest 객체에 담는다.
③ 담은 객체를 Main 메서드에 매개변수를 넘겨준다.
예시)
@Controller
public class RequestInfo{
@RequestMapping("/requestInfo")
public void main(HttpServletRequest request){
System.out.println(request.getMethod());
}
@Controller
public class RequestInfo {
@RequestMapping("/requestInfo")
// public static void main(String[] args) {
public void main(HttpServletRequest request) {
System.out.println("request.getCharacterEncoding()="+request.getCharacterEncoding()); // 요청 내용의 인코딩
System.out.println("request.getContentLength()="+request.getContentLength()); // 요청 내용의 길이. 알수 없을 때는 -1
System.out.println("request.getContentType()="+request.getContentType()); // 요청 내용의 타입. 알 수 없을 때는 null
System.out.println("request.getMethod()="+request.getMethod()); // 요청 방법
System.out.println("request.getProtocol()="+request.getProtocol()); // 프로토콜의 종류와 버젼 HTTP/1.1
System.out.println("request.getScheme()="+request.getScheme()); // 프로토콜
System.out.println("request.getServerName()="+request.getServerName()); // 서버 이름 또는 ip주소
System.out.println("request.getServerPort()="+request.getServerPort()); // 서버 포트
System.out.println("request.getRequestURL()="+request.getRequestURL()); // 요청 URL
System.out.println("request.getRequestURI()="+request.getRequestURI()); // 요청 URI
System.out.println("request.getContextPath()="+request.getContextPath()); // context path
System.out.println("request.getServletPath()="+request.getServletPath()); // servlet path
System.out.println("request.getQueryString()="+request.getQueryString()); // 쿼리 스트링
System.out.println("request.getLocalName()="+request.getLocalName()); // 로컬 이름
System.out.println("request.getLocalPort()="+request.getLocalPort()); // 로컬 포트
System.out.println("request.getRemoteAddr()="+request.getRemoteAddr()); // 원격 ip주소
System.out.println("request.getRemoteHost()="+request.getRemoteHost()); // 원격 호스트 또는 ip주소
System.out.println("request.getRemotePort()="+request.getRemotePort()); // 원격 포트
}
}
2. HttpServeltRequest 의 메서드
동적리소스( 실행할때마다 결과가 변함, 프로그램이 만들어냄, 스트리밍 )
메서드
설명
String year = String year = reqeust.getPrameter("year");