일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Lift
- 명사 분석기
- nodejs express
- node.js web framework
- iBatis
- Eclipse
- 책이야기
- ror실행
- 베트남어
- 명사 뽑아내기
- 디즈니씨
- ejb
- ajax
- rss
- flex3
- 명사 추출기
- 나의 취미
- express for node.js
- 나의 프로젝트
- C/C++
- 스킨 스쿠버
- php
- 도커
- Cross
- docker
- scala
- 메일왕창보내는법
- php thumbnail
- Node.js
- 주식이야기
- Today
- Total
nkdk의 세상
4번 getdata로 자료 보내서 주고 받기 본문
package nice;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LifeCycles extends HttpServlet {
public static int num;
public LifeCycles() {
super();
// 1
}
public void init() throws ServletException {
super.init();
num = 0;
System.out.println("init 수행 : 프로세스 생성");
// 2
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("service 수행 : 스레드 생성");
// 아래 2 문장은 자동으로 되기 때문에 쓰지 않아도 된다.
doGet(request, response);
doPost(request, response);
// 3
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 4
System.out.println("doPost 수행");
response.setContentType("text/html;charset=euc-kr");
PrintWriter out = response.getWriter();
num += 1;
Thread th = Thread.currentThread();
out.println("<html>라이프 사이클
");
out.println("변수 num = " + num);
out.println("
현재 스레드의 이름 : " + th.getName());
out.println("</html>");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 5
System.out.println("doGet 수행");
}
public void destroy() {
super.destroy();
// 6
}
}
//getData.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class getData extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=euc-kr");
request.setCharacterEncoding("euc-kr");
PrintWriter out = response.getWriter();
// 이렇게 받는다 getParameter로 받아서 처리 한다.
String irum = request.getParameter("name");
String addr = request.getParameter("addr");
String nai = request.getParameter("age");
int ss = Integer.parseInt(nai);
if(ss >= 20 && ss < 70) {
ss = (ss / 10) * 10;
} else ss = 0;
out.println("<html></html>");
out.println("*** 자료 뿌리기 ***
");
out.println("이름은 " + irum + "
");
out.println("주소는 " + addr + "
");
out.println("나이는 " + ss + "대 입니다
");
out.println("
자료다시 입력");
out.println("</html>");
}
}
// 이런식으로 sql과 비슷한 형식으로 파라미터를 받게 된다. 이제 추가적으로 쿠키 사용법과 여러가지 사용법을 익숙히 사용하면 될 듯 합니다.