<%@ 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>

분류 :

<select name="kind">

<option value="A" <% if(request.getParameter("kind")!=null) { if(request.getParameter("kind").equals("A") ) {%>selected<% } }%> >A항목</option>

<option value="B"<% if(request.getParameter("kind")!=null) { if(request.getParameter("kind").equals("B") ) {%>selected<% } }%>>B항목</option>

<option value="C"<% if(request.getParameter("kind")!=null) { if(request.getParameter("kind").equals("C") ) {%>selected<% } }%>>C항목</option>

</select>

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

</form>


</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>
<!--
포스트백 : 문서 자기자신에게 자료를 전송하는 형태를 일명 포스트백이라 부른다.
아래처럼 action속성에 문서자기자신의 이름을 지정하는 형태를 포스백이라 부른다.
form태그에서 method를 생략할 경우 기본값은 get이다.
form태그에서 action을 생략할 경우 기본값은 문서 자기자신.
-->
<% request.setCharacterEncoding("euc-kr"); %>
<form method="post" action="Intro09.jsp">
키워드 : <input type="text" name="keyword"  value="<% if(request.getParameter("keyword") != null ) { %><%=request.getParameter("keyword")%><% }  %>">
<input type="submit" value="확인">
</form>
입력한 값 :
<%//폼변수 keyword의 값을 출력
out.println(request.getParameter("keyword"));
%>
</body>
</html>
Posted by 말없제이
,
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!-- Intro07.jsp -->   
<!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>
<!-- 스파게티코드: 시작과 끝이 전부 html요소에 의해 분리되므로
어지러워서 스파게티코드라 부릅니다...  -->
<table width="650" border="1">
<%
for (int i=1; i<=10; i++)
{
%>
 <tr <% if (i%2==0) {%>bgcolor="yellow"<%} %>>
  <td><%=i %>행</td>
 </tr>
<%
}
%>
</table>
</body>
</html>

*.구구단 연습.
**********   Intro08.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>
<table border="1" width="650">
<%
 for (int i=1; i<=9; i++)
 {
%>  
<tr <% if (i%2==0) {%>bgcolor="green"<%} %>>
<%
  for (int j=1; j<=9; j++)
  {
%>  
   <td><%=i %>X<%=j %>=<%=(i*j) %></td>
<%
  }
%>
</tr>
<%
 }
%>
</table>
</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="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 말없제이
,

******* 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 말없제이
,
WebContent > WEB-INF > web.xml 파일내에..
사용자 삽입 이미지

설정한 순서로 나옴.

방법.
1. http://localhost:8000/jsp/intro/intro03.do 요청이 들어오면..
 요청에 맞는 url-pattern을 톰캣이 검색한다(절대 중복되어선 안됨) 허상.
2.url패턴과 같이 맞물려 있는 servlet-name을 읽어들인다.
3.servlet태그안에서 일치하는 servlet-name을 찾아서 같이 맞물려있는 서블릿 클래스를 읽어들인다.

ex>http://localhost:8000/jsp/baby/baby
같은경우 허상이라도..
url-pattern으로 접근이 가능함.
ex)
  <servlet-name>intro03</servlet-name>
  <servlet-class>intro.intro03</servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>intro03</servlet-name>
  <url-pattern>/baby/baby.do</url-pattern>
 </servlet-mapping>
Posted by 말없제이
,