Servlet사용 Post/Get방식 얻기
******* intro03.jsp *************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form method="get" action="intro03.do">
Get메시지 : <input type="text" name="message">
<input type="submit" value="확인">
</form>
</body>
</html>
******* intro04.jsp *************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="intro03.do">
Post메시지 : <input type="text" name="message">
<input type="submit" value="확인">
</form>
</body>
</html>
Servlet사용 Post/Get방식 얻기
**** src/intro/intro03.java *********
package intro;
//서블릿 프로그래밍시 필요한 참조패키지
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
//서블릿 클래스를 만들려면 HttpServlet클래스를 상속 받는 클래스를 만들면된다.
public class intro03 extends HttpServlet
{
//만일 서블릿이 다른 웹페이지로부터 자료를 전송받을때
//Get방식으로 자료를 전송받는다고 하면 상위클래스의
//doGet멤버함수를 오보라이딩 하면 된다.
//(자료를 전송받지 않을 경우 기본값은 Get방식으로 간주되므로 doGet이 실행된다)
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO 자동 생성된 메소드 스텁
//super.doGet(arg0, arg1);
//HttpServletRequest클래스 : 웹페이지의 입력과 관련된 클래스
//HttpServletResponse크래스 : 웹페이지의 출력과 관련 된 클래
//웹브라우저에 어떤 유형을 자료를 보낼것인지를 알려려주는
response.setContentType("text/html;charset=euc-kr");
PrintWriter out =response.getWriter();
out.print("<html>");
out.print("<head><title>결과</title></head>");
out.print("<body>");
out.print("메메시지 : "+request.getParameter("message"));
out.print("</dboy>");
out.print("</rml>");
//출력을 닫음.
out.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO 자동 생성된 메소드 스텁
//super.doPost(arg0, arg1);
response.setContentType("text/html;charset=euc-kr");
//웹페이지 출력에 관한 개체를 response로 부터 받는다.
request.setCharacterEncoding("euc-kr");
PrintWriter out =response.getWriter();
out.print("<html>");
out.print("<head><title>결과</title></head>");
out.print("<body>");
out.print("post 메시지 : "+request.getParameter("message"));
out.print("</dboy>");
out.print("</rml>");
//출력을 닫음.
out.close();
}
}