<%@ 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="Intro06pro.jsp">

노래 1 : <input type="text" name="sing"><p/>

노래 2 : <input type="text" name="sing"><p/>

노래 3 : <input type="text" name="sing"></p>

<input type="submit" value="확인">

</form>


</body>
</html>

************    Intro06pro.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>
<%
request.setCharacterEncoding("euc-kr");
%>
노래
<%
//문자열 배열로 받아서 반복하여 출력할것..
//★ 다중선택형 입력양식요소의 경우 선택하지 않은 요소는 값으로 넘어오지 않지만,
//아래와 같이 이름이 같은 단순텍스트상자의 경우 기입하지 않은 입력양식요소의 값도
//빈문자열로 전달된다.
String[] sings =request.getParameterValues("sing");
for(int i=0;i<sings.length;i++)
{
 out.println(sings[i]+", ");
}

out.println("갯수 : "+sings.length);
%>
</body>
</html>

Posted by 말없제이
,

<%@ 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 action="Intro05pro.jsp" method="post">
직업 <select name="job">
<option value="A">군인</option>
<option value="B">회사원</option>
<option value="C">프로그래머</option>
<option value="D">디자이너</option>
</select>
취미 <input type="radio"  name="hobby" value="1">낚시
<input type="radio"  name="hobby" value="2">독서
<input type="radio"  name="hobby" value="3">음악

관심분야
<input type="checkbox"  name="interest" value="1">패션
<input type="checkbox"  name="interest" value="2">음악
<input type="checkbox"  name="interest" value="3">게임
<p>
종아하는 음식 :
<select name="food" multiple="multiple" size="5">
<option value="1">자장면</option>
<option value="2">햄버거</option>
<option value="3">떡라면</option>
</select>
<input type="submit" value="확인">
</form>
</body>
</html>



************  Intro05pro.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>
<%
//JSP(Java Server Page) : 자바언어로 된 홈페이지 제작프로그래밍 언어(컴파일러)로
//서버에서 서블릿으로 변환되어 class로 컴파일되어 사용자에게
//웹페이지형태로 출력을 담당한다.
//실행순서는 위에서 시작되어서 아래로 쭈욱 내려가는 구조임
// % %는 원하면 여러번 사용이 가능.
%>

선택한 직업<% out.println(request.getParameter("job")); %><p>
선택한 취미<% out.println(request.getParameter("hobby")); %><p>
<%
//다중선택 양식요소는 request의 getParameterValues메서드를 사용하여
//여러개를 선택한 값들을 받아야 한다.
//다중선택요소의 경우 선택한 요소들만 배열로 넘어온다.
String[] interest = request.getParameterValues("interest");

for(int i=0;i<interest.length;i++)
{
  out.println(interest[i]+", ");
}
out.println("<p>갯수 : "+interest.length);
%>
관심분야 : <% out.println(request.getParameter("interest")); %><p>
<%
String[] foods = request.getParameterValues("food");
for(int i=0;i<foods.length;i++)
{
  out.println(foods[i]+", ");
}
out.println("<p>갯수 : "+foods.length);
%>
음식 : <% out.println(request.getParameter("food")); %><p>
</body>
</html>

Posted by 말없제이
,

package ch19;

import java.io.*;

public class Ch1908
{
 public static void main(String[] args) throws IOException
 {
  FileReader  in = new FileReader(new File("D:\\study\\java\\Project\\sample\\src\\ch19\\Ch1906.java"));
  int ch;
  StringBuffer stringBuffer = new StringBuffer();
  while((ch=in.read())!=-1)
  {
   stringBuffer.append((char)ch);
  }
  System.out.println(stringBuffer);
 
  FileWriter out = new FileWriter(new File("D:\\study\\java\\Project\\sample\\src\\ch19\\Output.java"));
  out.write(stringBuffer.toString());
  out.close();
 }
}

Posted by 말없제이
,

package ch19;

import java.io.*;

public class Ch1907
{
 public static void main(String[] args) throws IOException
 {
  //FileInputStream 클래스 : 텍스트화일 뿐만 아니라
  //바이너리화일까지 읽어들일 수 있다.
 
  FileInputStream in = new FileInputStream(new File("D:\\study\\java\\Project\\sample\\src\\ch19\\Ch1906.java"));
  int ch;
  //속도를 위해 StringBuilder 교체.
  //String result ="";
  StringBuilder result = new StringBuilder();
  while((ch=in.read())!=-1)
  {
   //속도를 위해 StringBuilder 교체.
   //result += (char)ch;
   result.append((char)ch);
  }
  in.close();
 
  System.out.println(result);
 
  FileOutputStream out = new FileOutputStream(new File("D:\\study\\java\\Project\\sample\\src\\ch19\\Output.java"));
  for(int i=0;i<result.length();i++)
  {
   ch=result.charAt(i);
   out.write(ch);
  }
  out.close();
 }
}

Posted by 말없제이
,

package ch19;

import java.io.*;

public class Ch1906
{
 public static void main(String[] args) throws IOException
 {
  //Reader시리즈 스트림클래스는 문자열처리에 적합
  InputStreamReader in = new InputStreamReader(System.in);
  int ch;
  String result="";
  while((ch=in.read())!= -1)
  {
   result +=(char)ch;  
  }
  System.out.println("result : "+result);
 
  OutputStreamWriter out = new OutputStreamWriter(System.out);
  out.write(result);
  out.close();
 }
}

Posted by 말없제이
,

package ch19;
//입출력스트림클래스 사용시 임포트할 패키지.
import java.io.*;

public class Ch1905
{

 public static void main(String[] args) throws IOException
 {
  //Stream이란 : 데이터와 데이터가 이동되는 연결되는 통로.
 
  //InputStream 클래스 : 입력스트리림중 가장 상위클래스이며
  //추상클래스 이므로 개체의 직접 생성이 불가능
 
  //Stream으로 시작되는 클래스는 바이너리데이터를 다루는데 유리
  //read() : 입력스트림에서 한글자를 읽어옴.
  //InputStream은 한글은 깨짐.
  InputStream in = System.in;
  int ch;
 
  String result="";
  //Ctrl-Z 누를때까지 무한반복한다.
  while((ch=in.read())!=-1)
  {
   result += (char)ch;
  }
 
  System.out.print("Result : "+result);
  in.close();
   
  // close없을경우 문제 발생 가능성있는 3가지.
  //1. 입출력 스트림
  //2. DB : webapplication
  //3. 통신
 
  //OutputStream : 출력스트림중 최상위 클래스로 추상 클래스
 
  //문자열 result를 콘솔출력에 내보내는 역활
  OutputStream out = System.out;
  for(int i=0;i<result.length();i++)
  {
   ch = result.charAt(i);
   out.write(ch);
   //용도를 알아보자꾸나. flush
   //out.flush();
  }
  //out.close();
 }
}

Posted by 말없제이
,

******* 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();
 }
 
}

Posted by 말없제이
,
<%@ 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="intro02pro.jsp">
id : <input type="text" name="id"><p/>
이름 : <input type="text" name="name"><p/>
Email: <input type="text" name="email"><p/>
<input type="submit" value="확인"><p/>
</form>
</body>
</html>

******* intro02pro.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>
<!--
Post방식일 경우에는 한글깨짐 문제를 해결하려면
아래의 메서드를 사용해야 한다.
한글이 euc-kr 아닐경우 에러..(비정상적인 글자)
-->
<% request.setCharacterEncoding("euc-kr"); %>
<% out.println(request.getParameter("id")); %><p/>
이름 : <% out.println(request.getParameter("name")); %><p/>
Email: <% out.println(request.getParameter("email")); %><p/>
</body>
</html>
Posted by 말없제이
,
<%@ 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="intro01pro.jsp">
id : <input type="text" name="id"><p/>
이름 : <input type="text" name="name"><p/>
Email: <input type="text" name="email"><p/>
<input type="submit" value="확인"><p/>
</form>
</body>
</html>
 
******* intro01pro.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>
<!--
한글이 깨지는 이유 :
웹브라우저(euc-kr)(8bit)  ------   ISO8859-1(7bit)   -------- 웹페이지
고로 Get방식에서의 한글 문제는 server.xml에 Connector태그에 URIEncoding="euc-kr"을 지정하면 해결.
<Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="8000" redirectPort="8443" URIEncoding="euc-kr"/>
id : -->
<% out.println(request.getParameter("id")); %><p/>
이름 : <% out.println(request.getParameter("name")); %><p/>
Email: <% out.println(request.getParameter("email")); %><p/>
</body>
</html>
Posted by 말없제이
,
<%@ 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>
<!--
?앞의 문자열 : 자료를 전송받는 웹페이지.
?뒤의 문자열 :  사용자가 입력한 값을 가지는 폼변수영역
http://search.naver.com/search.naver?where=nexearch&query=love&sm=top_hty&fbm=0
-->
<form method="get" action="http://search.naver.com/search.naver">
검색어 : <input type="text" name="query">
<input type="submit" value="확인">
</form>
<!--
http://search.daum.net/search?w=tot&t__nil_searchbox=btn&nil_id=tot&top_sp=0&stype=tot&q=love
-->
<form method="get" action="http://search.daum.net/search">
다음 검색어 : <input type="text" name="q">
<input type="submit" value="확인">
</form>
</body>
</html>
Posted by 말없제이
,