----test.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="ServletTest">
  1번 이름 : <INPUT TYPE="text" NAME="name1"/><p>


  <INPUT TYPE="submit" value="전송">
 </FORM>
</body>
</html>


-----ServletTest.java-----파일

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class for Servlet: testServlet
 *
 */
 public class ServletTest extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#HttpServlet()
  */
 public ServletTest() {
  super();
 }    
 
 /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doPost(request,response);

 }   
 
 /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
 
  PrintWriter out=response.getWriter();
  request.setCharacterEncoding("euc-kr");
 
  String name1=request.getParameter("name1");
 
  out.print(name1);

 }

     
}

 

//========================================================================================================================

 

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

               //name값 "name"에 해당하는 값을 String name 에 저장

request.setCharacterEncoding("euc-kr");

               //한글을 표현해주기위해사용


Dynamic Web Project 프로젝트 생성 후

test.jsp 파일은 WebContent 에서 생성

Java Resource : src 에서 servlet [ ServletTest.java ]파일 생성

서블릿 파일에서 doGet 메소드 안에 doPost(request,response); 정의

doPost 메소드 안에 출력 내용 정의


//----------doPost 안의 내용↓↓↓↓↓↓↓↓↓↓↓↓↓

PrintWriter out=response.getWriter();
request.setCharacterEncoding("euc-kr");  
String name1=request.getParameter("name1");
 
  out.print(name1);

//----------doPost 안의 내용↑↑↑↑↑↑↑↑↑↑↑↑↑

 

출력 클래스

import java.io.PrintWriter;

PrintWriter out=response.getWriter();

2010/01/11 13:07 2010/01/11 13:07

트랙백 주소 :: http://thinkit.or.kr/programming/trackback/15

댓글을 달아 주세요