블로그 이미지

마이실피르넷

일상의 이야기와 여러가지 유용한 정보들을 나누는 공간입니다. by 실피르넷


'학과수업들'에 해당되는 글 73건

  1. 2009/04/16 lex 실습 파일
  2. 2008/11/13 JDBC-ODBC, Access DB 연결 예제
  3. 2008/11/13 JDBC-ODBC , DB연결 예제
  4. 2008/11/06 ex. 간단한 달력
  5. 2008/11/06 ex. JSP 빈즈 프로그래밍
  6. 2008/11/06 ex. 유형2 - 계산기, JavaBean 이용
  7. 2008/11/06 ex. 유형1 - 계산기
  8. 2008/11/06 이클립스 wtp 다운로드
  9. 2008/10/30 JSP 내장 객체와 속성관리, 간단 예제
  10. 2008/10/29 실습7. 치환변수
  11. 2008/10/16 스크립틀릿, 표현식
  12. 2008/10/16 GET 방식, POST 방식
  13. 2008/10/16 ex3. application
  14. 2008/10/16 ex2. application
  15. 2008/10/16 ex. application p.203~205
  16. 2008/10/15 실습6. 보고서 형식
  17. 2008/10/13 자바 웹 프로그래밍 <1장 연습문제>
  18. 2008/10/12 C++ 프로그래밍 기초, 8장 연습문제
  19. 2008/10/10 C++ 프로그래밍 기초, 7장 연습문제
  20. 2008/10/09 ex4. session
  21. 2008/10/09 ex3. session
  22. 2008/10/09 ex2. session
  23. 2008/10/09 ex1. session
  24. 2008/10/02 예제 연습, Exam10
  25. 2008/10/02 예제 연습, Exam9
  26. 2008/10/02 예제 연습, Exam8
  27. 2008/10/02 예제 연습, Exam7
  28. 2008/10/02 예제 연습, Exam6
  29. 2008/10/02 p.183 참고하여 연습한 p.220 심화연습문제 1번
  30. 2008/09/19 자바 웹 프로그래밍 <5장 심화연습문제> 3번

lex 실습 파일

렉스 파일 : test.l 
%{ #include<stdio.h> #include<stdlib.h> enum tnumber { TEOF, TIDEN, TNUM, TASSIGN, TADD, TSEMI, TDOT, TBEGIN, TEND, TERROR}; %} letter [ a-zA-Z_] digit [0-9] %% begin return(TBEGIN); end return(TEND); {letter}({letter}|{digit})* return(TIDEN); ":=" return(TASSIGN); "+" return(TADD); {digit}+ return(TNUM); ";" return(TSEMI); \. return(TDOT); [ \t\n] ; . return(TERROR); %% void main() { enum tnumber tn; /*token number */ printf(" Start of Lex\n"); while((tn=yylex()) != TEOF) { switch(tn){ case TBEGIN : printf("Begin\n"); break; case TEND : printf("End\n"); break; case TIDEN : printf("Identifier: %s\n", yytext); break; case TASSIGN : printf("Assignment_op\n"); break; case TADD : printf("Add_op\n"); break; case TNUM : printf("Number: %d\n", atoi(yytext)); break; case TSEMI : printf("Semicolon\n"); break; case TDOT : printf("Dot\n"); break; case TERROR : printf("Error: %c\n", yytext[0]); break; } } } int yywrap() { printf(" End of Lex\n"); return 1; }

데이터 파일 : test.dat
begin
num := 0;
num := num + 526;
end.


compile
lex -otest.c test.l
cc test.c -o test -ll
test < test.dat
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/356 관련글 쓰기

Top

JDBC-ODBC, Access DB 연결 예제


<%@ page contentType="text/html; charset=euc-kr" import="java.sql.*" pageEncoding="euc-kr" %>
<% request.setCharacterEncoding("euc-kr"); %>

<%
	Connection conn = null;
	Statement stmt = null;
	String jdbc_driver = "sun.jdbc.odbc.JdbcOdbcDriver";
	String jdbc_url ="jdbc:odbc:sinDB";

	try
	{
		Class.forName(jdbc_driver);
		conn = DriverManager.getConnection(jdbc_url, "", "");
		stmt = conn.createStatement();
		if(request.getParameter("username") != null) {
			String sql = "insert into jdbc_test values('"+request.getParameter("username")+"','"+request.getParameter("email")+"')";
			stmt.executeUpdate(sql);
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
		out.println("연결실패 : "+ e.getMessage());
	}
%>

<html>
<head><title>JDBC 테스트</title></head>
<body>
<b><h2>이벤트 등록</h2></b>
<form name=form1 method=post action=jdbcRegister.jsp>
등록이름 : <input type=test name=username>
email주소 : <input type=text name=email size=20>
<input type=submit value="등록">
</form>
<br><br><br>
<b><h2>등록 목록</h2></b>
<%
	try{
		String sql2 = "select username, email from jdbc_test";
		ResultSet rs = stmt.executeQuery(sql2);
		int i=1;
		while(rs.next())
		{
			out.println(i+" : "+rs.getString(1)+" , "+rs.getString("email")+ "<br>");
			i++;
		}

		rs.close();
		stmt.close();
		conn.close();
	}
	catch(Exception e)
	{
		out.println(e);
	}
%>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/338 관련글 쓰기

Top

JDBC-ODBC , DB연결 예제


<%@ page contentType="text/html; charset=euc-kr" import="java.sql.*" pageEncoding="euc-kr" %>

<%
	Connection con = null;
	try
	{
		String jdbcUrl="jdbc:odbc:sinDB";
		out.println("1");
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		out.println("2");
		con = DriverManager.getConnection(jdbcUrl, "", "");
		out.println("연결되었습니다.");
	}
	catch(Exception e)
	{
		e.printStackTrace();
		out.println("연결실패1 : "+ e.getMessage());
	}
%>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/337 관련글 쓰기

Top

ex. 간단한 달력

cal.html

<%@ page contentType="text/html; charset=euc-kr" %>
<% request.setCharacterEncoding("euc-kr"); %>
<% response.setContentType("text/html; charset=euc-kr"); %>

<html>
<head>
<title>Welcome</title>
</head>
<body>

<center> 달력을 보자~
<br><br>
<a href="calin.jsp">달력보러가기</a>
</center>

</body>
</html>

calin.jsp

<%@ page contentType="text/html; charset=euc-kr" %>
<% request.setCharacterEncoding("euc-kr"); %>
<% response.setContentType("text/html; charset=euc-kr"); %>

<html>
<head>
<title>보고싶은 달을 쓰세요</title>
</head>
<body>

<h3><center> 보고싶은 달을 쓰세요 </center></h3>
<br><br>

<center>
<form action="calview.jsp" method="post">
<input type="text" name="year" size="4" maxlength="4" />
<input type="text" name="month" size="2" maxlength="2" />
<input type="submit" name="submit" size="4" value="보여주세요" />
</center>

</body>
</html>

calview.jsp

<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.util.Calendar" %>
<% request.setCharacterEncoding("euc-kr"); %>
<% response.setContentType("text/html; charset=euc-kr"); %>

<html>
<head>
<title>Calendar</title>
</head>
<body>

<center>

<%
String yyear = request.getParameter("year");
String mmonth = request.getParameter("month");
int year=2008, month=3;
try {
	year = Integer.parseInt(yyear.trim());
	month = Integer.parseInt(mmonth.trim());
}catch(Exception se){
}
%>

<table border="1" bgcolor="pink">
<%
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR,year);
cal.set(Calendar.MONTH,month-1); // 0~11월
cal.set(Calendar.DATE,1);
int statOfDay = cal.get(Calendar.DAY_OF_WEEK); // 1일이 어떤 요일
out.print("<tr><td colspan='7' align='center'>"+year+"년 "+month+"월 </td></tr>");
out.print("<tr><td>Sun</td><td>Mon</td><td>Tus</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>");
out.print("<tr>");
for(int i=1; i<statOfDay; i++){
	out.print("<td>&nbsp;</td>");
}

for(int i=1; i<=cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
	out.print("<td>"+i+"</td>");
	if((statOfDay-1+i) %7 ==0){
		out.print("</tr><tr>");
	}
}
out.print("</tr>");
%>
</table>

<form action="calin.jsp" method="post">
<input type="submit" name="submit" value="다른 달력 보기" /><br />
</form>

</center>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/334 관련글 쓰기

Top

ex. JSP 빈즈 프로그래밍

* WEB-INF 폴더 아래 classes에는 클래스파일, src에는 자바소스 파일
ex) login.LoginBean => classes/login/LoginBean.class

login_form.html

<html>
<head>
<title> JSP Bean example </title>
</head>

<body bgcolor="#FFFFFF">
<center>
<h2>로그인 예제</h2>
<hr>

<form method="post" action="login.jsp" name="form1">
	<table width="250" border="1" align="center" cellspacing="0" cellpadding="5">
	<tr>
	<td colspan="2" align="center">로그인</td>
	</tr>
	<tr>
	<td>아이디</td>
	<td><input type="text" name="userid" size="10"></td>
	</tr>
	<tr>
	<td>패스워드</td>
	<td><input type="password" name="passwd" size="10"></td>
	</tr>
	<tr>
	<td colspan="2" align="center">
	<input type="submit" name="submit" value="로그인"</td>
	</tr>
	</table>
</form>

</center>
</body>
</html>

login.jsp

<%@ page contentType="text/html; charset=euc-kr" %>
<jsp:useBean id="login" class="login.LoginBean" scope="page" />
<jsp:setProperty name="login" property="*" />

<html>
<head><title></title></head>
<body>
<center>
<h2>로그인 예제</h2>
<hr>

<%
	if(!login.checkUser()) {
		out.println("로그인 실패");
	}
	else {
		out.println("로그인 성공");
	}
%>

<hr>
사용자 아이디 : <jsp:getProperty name="login" property="userid" /><br>
사용자 패스워드 : <jsp:getProperty name="login" property="passwd" />

</center>
</body>
</html>

LoginBean.java

// 패키지 선언
package login;

// 클래스 선언
public class LoginBean {

	// 멤버 변수 선언
	private String userid;
	private String passwd;

	final String _userid = "myuser";
	final String _passwd = "1234";

	public boolean checkUser() {
		if(userid.equals(_userid)&&passwd.equals(_passwd)) {
			return true;
		}
		else
			return false;
	}

	public void setUserid(String userid){
		this.userid = userid;
	}

	public void setPasswd(String passwd){
		this.passwd = passwd;
	}

	public String getUserid(){
		return userid;
	}

	public String getPasswd(){
		return passwd;
	}
}

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/333 관련글 쓰기

Top

ex. 유형2 - 계산기, JavaBean 이용

실습시 editplus JAVA 컴파일 옵션 : -d d:/jspbook/WEB-INF/classes $(FilePath)
<%@ page contentType="text/html; charset=euc-kr" %> <jsp:useBean id="calc" scope="page" class="calc.CalcBean" /> <jsp:setProperty name="calc" property="*" /> <% calc.calculate(); %> <html> <head> <title> 계산기 </title> </head> <body> <center> <h3> 계산기 </h3> </hr> <form name="form1" method="post"> <input type="text" name="num1" width="200" size="5"> <select name="operator"> <option selected>+</option> <option>-</option> <option>*</option> <option>/</option> </select> <input type="text" name="num2" width="200" size="5"> <input type="submit" value="계산" name="b1"> <input type="reset" value="다시 입력" name="b2"> </form> <hr> 계산결과 : <jsp:getProperty name="calc" property="result" /> </body> </html>

package calc;

public class CalcBean
{
	private int num1, num2;
	private String operator="";
	private int result;
	
	public void calculate(){
		if(operator.equals("+")){
			result = num1 + num2;
		}
		else if(operator.equals("-")){
			result = num1 - num2;
		}
		else if(operator.equals("*")){
			result = num1 * num2;
		}
		else if(operator.equals("/")){
			result = num1 / num2;
		}
	}

	public void setNum1(String num1){
		this.num1 = Integer.parseInt(num1);
	}
	public void setNum2(String num2){
		this.num2 = Integer.parseInt(num2);
	}
	public void setOperator(String operator){
		System.out.println("## "+operator);
		this.operator = operator;
	}

	public int getResult(){
		return result;
	}
}

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/332 관련글 쓰기

Top

ex. 유형1 - 계산기


<%@ page contentType="text/html; charset=euc-kr" %>

<%
	// 변수 설정
	int result = 0;

	// 웹 페이지 요청이 POST인 경우에만 수행,
	// 즉 폼(Form)을 통해 전달된 것만 수행
	// 초기 로딩 시 오류 방지
	if(request.getMethod().equals("POST")) {

		// 연산자를 가져옴
		String op = request.getParameter("operator");

		// 문자열 형태로 전달된 인자들을 int로 변환함
		int num1 = Integer.parseInt(request.getParameter("num1"));
		int num2 = Integer.parseInt(request.getParameter("num2"));

		// 각 연산자별 처리
		if (op.equals("+")) {
			result = num1 + num2;
		}
		else if(op.equals("-")) {
			result = num1 - num2;
		}
		else if(op.equals("*")) {
			result = num1 * num2;
		}
		else if(op.equals("/")) {
			result = num1 / num2;
		}
	}
%>

<html>
<head>
<title> 계산기 </title>
</head>

<body>
<center>
<h3> 계산기 </h3>
</hr>
<form name="form1" method="post">
<input type="text" name="num1" width="200" size="5">
<select name="operator">
	<option selected>+</option>
	<option>-</option>
	<option>*</option>
	<option>/</option>
</select>

<input type="text" name="num2" width="200" size="5">
<input type="submit" value="계산" name="b1"> <input type="reset" value="다시 입력" name="b2">
</form>
<hr>

계산결과 : <%=result %>
</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/331 관련글 쓰기

Top

이클립스 wtp 다운로드

http://www.eclipse.org/downloads/download.php?file=/webtools/downloads/drops/R3.0/R-3.0.2-20080921203356/wtp-sdk-R-3.0.2-20080921203356.zip

이클립스 톰캣 6.0 설정
http://blog.naver.com/look4luck?Redirect=Log&logNo=140042886220

이클립스 톰캣 플러그인
http://www.eclipsetotale.com/tomcatPlugin.html

1. 압축 풀면 com.sysdeo.eclipse.tomcat_3.2.1 이 나온다.
2. 이클립스를 설치한 폴더의 plugins 폴더(예 : c:\eclipse\plugins) 안에 붙여넣기 한다.
3. 이클립스를 실행시키면 톰캣 "Start Tomcat", "Stop Tomcat", "Restart Tomcat" 메뉴가 생겼다.

톰캣 플러그인 설치 방법
http://blog.naver.com/sungback?Redirect=Log&logNo=90003125749

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/330 관련글 쓰기

Top

JSP 내장 객체와 속성관리, 간단 예제


<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" %>

<html>
<head>
<title> login.jsp </title>
</head>
<body>

<center>
	<h2>로그인</h2>
	<form name="form1" method="post" action="selProduct.jsp">
		<input type="text" name="username"/>
		<input type="submit" value="로그인"/>
	</form>
</center>

</body>
</html>


<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" %>

<html>
<head>
<title> selProduct.jsp </title>
</head>
<body>

<%
	//HTML 폼에서 전달된 데이터의 한글 인코딩
	request.setCharacterEncoding("euc-kr");

	//session에 username 이름으로 HTML 폼의 <input type="text" name="username" />에 입력된 값을 저장함.
	session.setAttribute("username",request.getParameter("username"));
%>

<center>
	<h2>상품 선택</h2>
	<hr>
	<%=session.getAttribute("username") %>님이 로그인한 상태입니다.
	<form name="form1" method="post" action="add.jsp">
		<select name="product">
			<option>사과</option>
			<option></option>
			<option>파인애플</option>
			<option>자몽</option>
			<option>레몬</option>
		</select>
		<input type="submit" value="추가"/>
	</form>
	<a href="checkOut.jsp">계산</a>
</center>

</body>
</html>


<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.ArrayList" %>

<html>
<head>
<title> add.jsp </title>
</head>
<body>

<%
	//HTML 폼에서 전달된 데이터의 한글 인코딩
	request.setCharacterEncoding("euc-kr");

	String productname = request.getParameter("product");
	ArrayList list = (ArrayList) session.getAttribute("productlist");
	if(list == null){
		list = new ArrayList();
	}
	list.add(productname);
	session.setAttribute("productlist",list);
%>

	<script>
		alert("<%=productname %>이(가) 추가되었습니다!!");
		history.go(-1);
	</script>

</body>
</html>


<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.ArrayList" %>

<html>
<head>
<title> checkOut.jsp </title>
</head>
<body>

<center>
<h2>계산</h2>
선택한 상품 목록
<hr>
<%
	ArrayList list = (ArrayList) session.getAttribute("productlist");
	if(list == null){
		out.println("선택한 상품이 없습니다.!!!");
	}
	else {
		for(Object productname:list){
			out.println(productname+"<br>");
		}
	}
%>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/329 관련글 쓰기

Top

실습7. 치환변수

실습7

4번. 쿼리문

SET ECHO OFF
SET VERIFY OFF
ACCEPT low_date_range PROMPT 'Enter the low date range (DD-MON-YY) : '
ACCEPT high_date_range PROMPT 'Enter the high date range (DD-MON-YY) : '

select userid "USERID", first_name ||' '|| last_name "EMPLOYEE", start_date "START_DAT" from s_emp where start_date between '&low_date_range' and '&high_date_range'
/


5번. 쿼리문

SET ECHO OFF
SET VERIFY OFF

ACCEPT c_name PROMPT "Please enter the customer's name : "

select id "ID", name "CUSTOMER NAME" from s_customer where lower(name) like lower('%&c_name%')
/


6번. 쿼리문

SET ECHO OFF
SET PAGES 25
SET LINES 80
SET FEEDBACK OFF
SET VERIFY OFF

ACCEPT c_name PROMPT "Please enter a customer's name : "

COL "c_title" HEA "Sales rep for customer's whose name contains '&c_name'" FORMAT A52
COL "ORDER_ID" FORMAT 999
COL "CUSTOMER" FORMAT A20
COL "PRODUCT" FORMAT A25

BREAK ON "ORDER_ID" SKIP 1 ON REPORT ON "CUSTOMER"

select e.first_name||' '||e.last_name||'is the rep to '||c.name "c_title" from s_emp e, s_customer c where e.id=c.sales_rep_id and lower(c.name) like lower('%&c_name%')
/

select o.id "ORDER_ID", c.name "CUSTOMER", p.name "PRODUCT" from s_ord o, s_customer c, s_product p, s_item i where o.customer_id = c.id and o.id = i.ord_id and p.id = i.product_id and lower(c.name) like lower('%&c_name%')
/


7번. 쿼리문

SET ECHO OFF
SET PAGES 25
SET LINES 80
SET FEEDBACK OFF
SET VERIFY OFF

COL EMPLOYEE FORMAT A15
COL CUSTOMER FORMAT A30
COL SALES FORMAT $9,999,999

BREAK ON "EMPLOYEE" SKIP 1 ON REPORT
COMPUTE SUM LABEL 'sum' OF "SALES" ON REPORT

select e.first_name ||' '|| e.last_name "EMPLOYEE", c.name "CUSTOMER", sum(o.total) "SALES"
from s_emp e, s_customer c, s_ord o
where e.id = c.sales_rep_id and o.customer_id = c.id and c.region_id = &1
group by e.first_name ||' '|| e.last_name, c.name
order by c.name
/

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/328 관련글 쓰기

Top

스크립틀릿, 표현식

선언
<%! 내용 %>

스크립틀릿
<% out.println(new java.util.Data()); %>

표현식
<%= new java.util.Data() %>
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/326 관련글 쓰기

Top

GET 방식, POST 방식

[GET 방식]
- 서버에 있는 정보를 가져오기 위해 설계된 방법.
- 서버로 전달할 수 있는 데이터 크기 최대 240Byte까지 가능.
- URL이 노출되기 때문에 보안 문제가 생길 수 있다.

[POST 방식]
- 서버로 정보를 올리기 위해 설계된 방법
- 서버에 전달할 수 있는 데이터 크기에 제한이 없다.
- URL에는 파라미터가 표시되지 않는다.
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/325 관련글 쓰기

Top

ex3. application


<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr"%>

<html>
<head><title> application attributes </title></head>
<body>

<% String rpath = application.getRealPath("/"); %>
실제 경로명 : <%= rpath %> <br>
<% rpath = application.getRealPath("/jspbook/"); %>
실제 경로명 : <%= rpath %> <br>
<% rpath = application.getRealPath("/jspbook/ex0511.html"); %>
파일의 MIME : <%= application.getMimeType(rpath) %><br>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/324 관련글 쓰기

Top

ex2. application


<%@ page contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.io.*" %>

<%
String sData, aData;
sData = "안녕 세션";
aData = "안녕 어플리케이션";
session.setAttribute("sData", sData);
application.setAttribute("aData", aData);
%>

<html>
<head><title> session and application attributes </title></head>
<body>
<center>
세션과 어플리케이션 속성을 설정하였습니다.<br>
<a href="application2_result.jsp">같은 세션에서 확인하기</a>
</center>

</body>
</html>



<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.*" %>

<%
Enumeration atts;
String key;
%>

<html>
<head><title> session and application attributes </title></head>
<body>
<b>세션 속성들 : </b><br>
<%
atts = session.getAttributeNames();
while ( atts.hasMoreElements() ) {
	key = (atts.nextElement() ).toString();
%>
<%= key %> = <%= session.getAttribute(key) %> <br>
<% } %>
<br>
<b>어플리케이션 속성들 : </b><br>
<%
atts = application.getAttributeNames();
while ( atts.hasMoreElements() ) {
	key = (atts.nextElement() ).toString();
%>
<%= key %> = <%= application.getAttribute(key) %> <br>
<% } %>
<br>

</body>
</html>



<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.*" %>

<html>
<head><title> session and application attributes </title></head>
<body>
<%
session.removeAttribute("sData");
application.removeAttribute("aData");
%>

<b>세션 속성들 : </b><br>
<%
Enumeration atts;
String key;

atts = session.getAttributeNames();
while ( atts.hasMoreElements() ) {
	key = (atts.nextElement() ).toString();
%>
<%= key %> = <%= session.getAttribute(key) %> <br>
<% } %>
<br>
<b>어플리케이션 속성들 : </b><br>
<%
atts = application.getAttributeNames();
while ( atts.hasMoreElements() ) {
	key = (atts.nextElement() ).toString();
%>
<%= key %> = <%= application.getAttribute(key) %> <br>
<% } %>
<br>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/323 관련글 쓰기

Top

ex. application p.203~205


<%@ page contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.io.*" %>

<html>
<head><title> </title></head>
<body>

<center>
<h2>application 예제</h2>
<hr>
1. 서버 정보 : <%= application.getServerInfo() %> <br>
2. 서블릿API 버전 정보 : <%= application.getMajorVersion()+"."+application.getMinorVersion() %> <br> 
3. application.jsp 파일의 실제 경로 : <%= application.getRealPath("application.jsp") %> <br>

<hr>
setAttribute로 username 변수에 "홍길동" 설정<p>
<% 
	application.setAttribute("username","홍길동");
	application.log("username=홍길동");
	application.setAttribute("count",1);
%>

<a href="application_result.jsp"> 확인하기 </a>
</center>

</body>
</html>




<%@ page contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.io.*" %>

<html>
<head><title> application_result.jsp </title></head>
<body>

<center>
<h2>application 예제</h2>
<hr>
username에 설정된 값은 : <%= application.getAttribute("username") %> <p>
<%
	Integer count = (Integer)application.getAttribute("count");
	int cnt = count.intValue()+1;
	application.setAttribute("count",cnt);
%>
방문자수 : <%= cnt %>
</center>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/321 관련글 쓰기

Top

실습6. 보고서 형식

실습6.
3번 쿼리문

SET ECHO OFF
SET PAGES 28
SET LINES 70
SET FEEDBACK OFF

TTI CENTER 'Sales Representatives' SKIP 1 CENTER 'And Customers' SKIP 2
BTI RIGHT 'Page' SQL.PNO SKIP 1

COL "Sales Rep" FORMAT A30
COL name HEA 'Customer' FORMAT A30

BREAK ON "Sales Rep" SKIP 1 ON REPORT
COMPUTE COUNT LABEL 'TOTAL CUSTOMERS' OF name ON REPORT

select upper(s_emp.last_name) || ' is the rep for' "Sales Rep", s_customer.name from s_emp, s_customer where s_emp.id = s_customer.sales_rep_id order by s_emp.last_name, s_customer.name
/


4번 쿼리문

SET ECHO OFF
SET PAGES 45
SET LINES 55
SET FEEDBACK OFF

TTI 'Sales|Report'

COL "Sales Rep" HEA 'Sales|Rep' FORMAT 9999999
COL "Customer name" HEA 'Customer|name' FORMAT A20
COL "Order Date" HEA 'Order|Date' FORMAT A10
COL "Total" FORMAT $9,999,999.99

BREAK ON "Sales Rep" SKIP 1 ON REPORT ON "Customer name" ON NODUP
COMPUTE SUM LABEL 'sum' OF "Total" ON "Sales Rep"
COMPUTE SUM LABEL 'sum' OF "Total" ON REPORT

select o.sales_rep_id "Sales Rep", upper(c.name) "Customer name", to_char(o.date_ordered, 'mm/dd/yy') "Order Date", o.total "Total" from s_ord o, s_customer c where o.customer_id=c.id order by "Sales Rep", "Customer name"
/

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/320 관련글 쓰기

Top

자바 웹 프로그래밍 <1장 연습문제>

<1장 연습문제>

1. HTTP가 무엇의 약자인지 쓰고, 그것에 대해 설명하라.
HTTP(HyperText Transfer Protocol)
네트워크로 연결된 컴퓨터가 서로 통신하려면 언어와 같은 규약이 필요하고
이러한 규약을 프로토콜이라 하며, WWW서비스를 규정하는 프로토콜이 HTTP다.

2. 웹 서비스(WWW)를 제공하기 위해 필요한 소프트웨어를 통칭하는 용어는 무엇인가? 또한 대표적인 소프트웨어를 한 가지 써라.
WWW서비스를 제공하는 소프트웨어를 “웹 서버 소프트웨어”라고 하며
대표적인 웹 서버 소프트웨어로는 아파치(Apache)가 있다.

3. 웹 브라우저에서 표현되는 화면을 기술하기 위해 사용하는 언어를 무엇이라 하는가?
HTML(HyperText Markup Lanauage)은 WWW 서비스를 표현하기 위해 사용하는 언어다.
HTML의 단점을 극복하는 방안으로 웹과 기존 프로그래밍 환경을 연결해주는 CGI와 같은 기술이 등장하였고, 서버 스크립트 기술로 웹 페이지에 함께 작성할 수 있는 기술로 PHP,ASP,JSP등이 있다.

4. Ajax와 Google API로 대표되는 차세대 웹 기술에 대한 통칭을 무엇이라 하는가?
Web 2.0은 2004년 처음 등장한 용어로 가벼운 프로그래밍 모델, 신디케이션, 개조와 재조합이 가능한 설계를 기반으로 하는 차세대 웹 기술을 의미한다.

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/319 관련글 쓰기

Top

C++ 프로그래밍 기초, 8장 연습문제


// 1. 다음 프로그램을 실행하면 에러가 발생한다. 에러가 발생하지 않도록 수정하라.

#include<iostream>
using namespace std;
class CRect
{
public : 
	void print();
	//int left; //public으로 정의
	//int top; //public으로 정의
	//int right; //public으로 정의
	//int bottom; //public으로 정의
}; void CRect::print() { cout << "(" << left << ", " << top<< ", " << right << ", " << bottom << " )" <<endl; } void main() { CRect obj_1; obj_1.left=0; obj_1.top=0; //error obj_1.right=20; obj_1.bottom='20'; //error obj_1.print(); }

// 1. 다음 프로그램을 실행하면 에러가 발생한다. 에러가 발생하지 않도록 수정하라.
// (데이터 은닉 private 접근 지정자를 유지하면서 private 멤버 변수값을 수정하기
// 위해서 멤버함수를 추가하는 방법)

#include<iostream>
using namespace std;
class CRect
{
	int left;
	int top;
	int right;
	int bottom;
public : 
	void print();
	void setLeft(int l); //멤버함수 추가
	void setTop(int t); //멤버함수 추가
	void setRight(int r); //멤버함수 추가
	void setBottom(int b); //멤버함수 추가
};

void CRect::setLeft(int l){left = l;} //멤버함수 추가
void CRect::setTop(int t){top = t;} //멤버함수 추가
void CRect::setRight(int r){right = r;} //멤버함수 추가
void CRect::setBottom(int b){bottom = b;} //멤버함수 추가

void CRect::print()
{
	cout << "(" << left << ", " << top<< ", " << right << ", " << bottom << " )" <<endl;
}

void main()
{
	CRect obj_1;
	obj_1.setLeft(0); obj_1.setTop(0); //error
	obj_1.setRight(20); obj_1.setBottom(20); //error
	obj_1.print();
}

// 2. SetRect()를 멤버함수로 정의하라.

#include <iostream>
using namespace std;
class CRect
{
	int left;
	int top;
	int right;
	int bottom;

	public :
		void print();
		void SetRect(int l, int t, int r, int b);
};

// SetRect()를 멤버함수로 정의
void CRect::SetRect(int l, int t, int r, int b)
{
	this->left = l; 
	this->top = t;
	this->right = r;
	this->bottom = b; 
}
// SetRect()를 멤버함수로 정의 끝

void CRect::print()
{
	cout << "(" << left << ", " << top<< ", " << right << ", " << bottom << " )" <<endl;
}

void main()
{
	CRect obj_1;
	obj_1.SetRect(0, 0, 20, 20); //error
	obj_1.print();
}

// 3. 객체를 초기화할 수 있도록 생성자를 오버로딩하라.

#include <iostream>
using namespace std;
class CRect
{
	int left;
	int top;
	int right;
	int bottom;

	public :
		void prn();
		CRect(int l, int t, int r, int b);
		CRect(int r, int b);
		CRect();
};

CRect::CRect(int l, int t, int r, int b)
{
  left=l;
  top=t;
  right=r;
  bottom=b;
}

CRect::CRect(int r, int b)
{
  left=0;
  top=0;
  right=r;
  bottom=b;
}

CRect::CRect()
{
  left=0;
  top=0;
  right=0;
  bottom=0;
}

void CRect::prn()
{
	cout << "(" << left << ", " << top<< ", " << right << ", " << bottom << " )" <<endl;
}

void main()
{
	CRect obj_1(0, 0, 20, 20);
	CRect obj_2(20, 20);
	CRect obj_3;
	obj_1.prn();
	obj_2.prn();
	obj_3.prn();
}

// 4. 객체를 초기화할 수 있도록 생성자에 디폴드 매개변수 값으로 할당받도록 정의하라.

#include <iostream.h>
#include <iomanip.h>

class CRect
{
	int left;
	int top;
	int right;
	int bottom;

	public : 
		void prn();
		CRect(int l=0, int t=0, int r=0, int b=0);
};

CRect::CRect(int l, int t, int r,  int b) 
{
	left=l;
	top=t;
	right=r;
	bottom=b;
}

void CRect::prn()
{
	cout << "(" << left << ", " << top<< ", " << right << ", " << bottom << " )" <<endl;
}

void main()
{
	CRect obj_1(20, 20, 20, 20);
	CRect obj_2(20, 20, 20);
	CRect obj_3(20, 20);
	CRect obj_4(20);
	CRect obj_5;
	obj_1.prn();	obj_2.prn();	obj_3.prn();
	obj_4.prn();	obj_5.prn();
}

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/318 관련글 쓰기

Top

C++ 프로그래밍 기초, 7장 연습문제


#include<iostream>

using namespace std;

struct sungjuk{
	char name[20];
	int kor;
	int eng;
	int mat;
	int tot;
	double ave;
};

void totAve(sungjuk &s);
void prn(sungjuk s);

void main()
{
	sungjuk s = {"성윤정",100,80,95};
	totAve(s); //총점과 평균
	prn(s); //출력
}

void totAve(sungjuk &s)
{
	s.tot = s.kor + s.eng + s.mat;
	s.ave = s.tot / 3.0;
}

void prn(sungjuk s)
{
	cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
	cout<<"\n -------------------------------------------";
	cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}




#include<iostream>

using namespace std;

struct sungjuk{

	char name[20];
	int kor;
	int eng;
	int mat;
	int tot;
	double ave;
};

void init(sungjuk &s);
void totAve(sungjuk &s);
void prn(sungjuk s);

void main()
{
	sungjuk s;
	init(s);
	totAve(s); //총점과 평균
	prn(s); //출력
}

void init(sungjuk &s)
{
	cout<<"이름을 입력하세요.-> ";
	cin>>s.name;
	cout<<"국어 점수를 입력하세요.-> ";
	cin>>s.kor;
	cout<<"영어 점수를 입력하세요.-> ";
	cin>>s.eng;
	cout<<"수학 점수를 입력하세요.-> ";
	cin>>s.mat;
}

void totAve(sungjuk &s)
{
	s.tot = s.kor + s.eng + s.mat;
	s.ave = s.tot / 3.0;
}

void prn(sungjuk s)
{
	cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
	cout<<"\n -------------------------------------------";
	cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}




#include<iostream>

using namespace std;

struct sungjuk{
	char name[20];
	int kor;
	int eng;
	int mat;
	int tot;
	double ave;
};

void init(sungjuk s);
void totAve(sungjuk &s);
void prn(sungjuk s);

void main()
{
	sungjuk s[5];

	for(int i=0; i<5; i++){
		init(s[i]);
	}
}

void init(sungjuk s)
{
	cout<<"이름을 입력하세요.-> ";
	cin>>s.name;
	cout<<"국어 점수를 입력하세요.-> ";
	cin>>s.kor;
	cout<<"영어 점수를 입력하세요.-> ";
	cin>>s.eng;
	cout<<"수학 점수를 입력하세요.-> ";
	cin>>s.mat;
	cout<<"\n";
	totAve(s);
	prn(s);
}

void totAve(sungjuk &s)
{
	s.tot = s.kor + s.eng + s.mat;
	s.ave = s.tot / 3.0;
}

void prn(sungjuk s)
{
	cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
	cout<<"\n -------------------------------------------";
	cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/317 관련글 쓰기

Top

ex4. session


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>

<%
String id=session.getId();
out.print("생성된 세션 아이디는"+id+"<br>");
// session.invalidate(); //세션 무효화
session.setAttribute("memberID","zino");
String memberID = (String)session.getAttribute("memberID");
out.print("세션에 부여된 memberID 변수값은 "+memberID+"입니다.");
%>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/316 관련글 쓰기

Top

ex3. session


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>

<%
// 1분 이상 사용하지 않으면 세션을 종료한다.
session.setMaxInactiveInterval(60);
%>

<html>
<head>
<title> session methods (2) </title>
</head>
<body>

<center>
[session 정보]<br>
ID : <%= session.getId() %> <br>
마지막 요청한 시간 : <%= session.getLastAccessedTime() %> <br>
세션 종료 기준(변경된 값) :<%= session.getMaxInactiveInterval() %> <br>
<br>
<br>
1분 이상 지난후에 새로고침 버튼을 클릭하면 새로운 세션이기 때문에 세션 ID가 바뀐다.
</center>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/315 관련글 쓰기

Top

ex2. session


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>

<html>
<head>
<title> session methods </title>
</head>
<body>

<center>
[session 정보]<br>
ID : <%= session.getId() %> <br>
생성된 시간 : <%= session.getCreationTime() %> <br>
마지막 요청한 시간 : <%= session.getLastAccessedTime() %> <br>
세션 종료 기준(디폴트 값) :<%= session.getMaxInactiveInterval() %> <br>
</center>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/314 관련글 쓰기

Top

ex1. session


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>

<html>
<head>
<title> session.jsp </title>
</head>
<body>

<center>
<h2> session 예제 </h2>
<hr>
<%
	// isNew() 메서드를 이용해 최초세션설정을 확인하고 있다.
	if(session.isNew()) {
		out.println("<script> alert('세션이 해제되어 다시 설정합니다.') </script>");
		session.setAttribute("login","홍길동");
		//session.setMaxInactiveInterval(5);
	}
%>

# <%= session.getAttribute("login") %> 님 환영 합니다.<br>
1. 세션 ID : <%= session.getId() %> <br>
2. 세션 유지시간 : <%= session.getMaxInactiveInterval() %><br>
</center>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/313 관련글 쓰기

Top

예제 연습, Exam10


<%@ page language="java" contents="text/html; charset=euc-kr" pageEncoding="euc-kr" %>
<%@ page autoFlush="false" %>

<html>
<head>
<title>Buffering</title>
</head>
<body>

isAutoFlush : <%= out.isAutoFlush() %><br>
<i>버퍼링 사용법</i><br>
1. 오늘 아침은 기분이 좋았다.<br>
<%
out.flush();
out.println("점심을 먹을 시간이다."); 
%>
2. 오늘 점심은 맛있는 음식을 먹었다.<br>
<%
out.clearBuffer();
%>
3. 오늘 저녁은 옛 친구를 만났다.
</body>
</html>
<%
out.close();
%>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/312 관련글 쓰기

Top

예제 연습, Exam9

exam9.jsp
<%@ page import="java.util.*" %>

<html>
<head>
<title>Data Class</title>
</head>
<body>

<%
Date date = new Date();
%>
<%-- 현재의 시각을 출력한다. --%>
오늘은 <%= date %> 입니다.
오늘은 <%= 1900 + date.getYear() %>
       <%= 1 + date.getMonth() %>
	   <%= date.getDate() %>일입니다.

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/311 관련글 쓰기

Top

예제 연습, Exam8

exam8.jsp
<% response.setContentType("text/html"); response.setHeader("Favorite-Coffee", "choice"); %> <html> <head> <title>Response Headers</title> </head> <body> Content의 문자열 인코딩 방식 : <%= response.getCharacterEncoding() %><br> Favorite-Coffee 헤더 ? : <%= response.containsHeader("Favorite-Coffee") %><br> Good-Morning 헤더 ? : <%= response.containsHeader("Good-Morning") %><br> </body> </html>
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/310 관련글 쓰기

Top

예제 연습, Exam7

exam7_form.html

<html>
<head>
<title>request Methods(Form-etc)</title>
</head>
<body>

<form method="post" action="exam7_view.jsp">
당신의 국적을 선택하세요.<br>
<input type="radio" name="country" value="korea" checked>한국</input>
<input type="radio" name="country" value="america">미국</input>
<br>
<input type="submit" value="전송">
</form>

</body>
</html>

exam7_view.jsp

<html>
<head>
<title>request Methods(Result-etc)</title>
</head>
<body>

Remote Host : <%= request.getRemoteHost() %> <br>
Remote Addr : <%= request.getRemoteAddr() %> <br>
Server Host : <%= request.getServerName() %> <br>
Server Addr : <%= request.getServerPort() %> <br>
<br>
Request Method : <%= request.getMethod() %> <br>
Content Type : <%= request.getContentType() %> <br>
Query String : <%= request.getQueryString() %> <br>
Content Length : <%= request.getContentLength() %> <br>
Request URI : <%= request.getRequestURI() %> <br>
Servelet Path : <%= request.getServletPath() %> <br>
</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/308 관련글 쓰기

Top

예제 연습, Exam6

exam6_form.html

<html>
<head>
<title>Enumeration usage (Form-input)</title>
</head>
<body>

<form method="post" action="exam6_view.jsp">
응시한 과목들을 선택하세요. (복수선택 가능)<br>
<input type="checkbox" name="test" value="국어">국어</input>
<input type="checkbox" name="test" value="영어">영어</input>
<input type="checkbox" name="test" value="수학">수학</input>
<input type="checkbox" name="test" value="과학">과학</input>
<br>
응시한 소감을 적으세요.<br>
<textarea name="contents" rows=4 cols=40></textarea><br>
암호 : <input type="password" name="password" size=10></input>
<input type="submit" value="전송">
</form>

</body>
</html>


exam6_view.jsp

<%@ page import="java.util.*" %>

<%
Enumeration keys;
String key;
String[] values;
String value;
%>

<html>
<head>
<title>Enumeration usage(Result)</title>
</head>
<body>

<!-- 반복문을 이용해 hasM<oreElements 다음 요소가 있는지 찾아주는것 -->

<%
for(keys = request.getHeaderNames(); keys.hasMoreElements();) {
	key = (keys.nextElement()).toString();
%>
<%= key %> : 
<% value = request.getHeader(key); %>
<%= value %> <br>
<% } %>

<br>

<%
for(keys = request.getParameterNames(); keys.hasMoreElements();) {
	key = (keys.nextElement()).toString();
%>
<%= key %> : 
<% 
	values = request.getParameterValues(key);
	for(int i=0; i<values.length; i++) {
%>
&nbsp;<%= values[i] %>
<% } %>
<br>
<% } %>

</body>
</html>

Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/307 관련글 쓰기

Top

p.183 참고하여 연습한 p.220 심화연습문제 1번

exam5_form.html 파일
<html> <head> <title>Exam5</title> </head> <body> <center> <h2>Exam5</h2> <hr> <form name=form1 method=post action=exam5_view.jsp> <table border=1 cellspacing=1 cellpadding=5> <tr> <td>이름</td> <td><input type=text size=10 name=username></td> <tr> <td>직업</td> <td> <input type=radio name=job value="무직">무직</input> <input type=radio name=job value="회사원">회사원</input> <input type=radio name=job value="전문직">전문직</input> <input type=radio name=job value="학생">학생</input> </td> <tr> <td>관심분야</td> <td> <input type=checkbox name=favorite value="정치">정치</input> <input type=checkbox name=favorite value="사회">사회</input> <input type=checkbox name=favorite value="정보통신">정보통신</input> </td> </tr> <tr><td colspan=2 align=center><input type=submit value="확인"><input type=reset value="취소"></td></tr> </form> </body> </html>
exam5_view.jsp 파일
<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" %> <% request.setCharacterEncoding("euc-kr"); %> <html> <head> <title></title> </head> <body> <center> <h2>Exam5 결과</h2> <hr> <table border=1 cellspacing=1 cellpadding=5> <tr> <td>이름</td> <td><%=request.getParameter("username") %></td> </tr> <tr> <td>직업</td> <td><%=request.getParameter("job") %></td> </tr> <tr> <td>관심분야</td> <td> <% // getParameterValues 메서드를 이용해 "favorite"로 설정된 폼의 체크박스 값들을 모두 읽어옴" String favorites[] = request.getParameterValues("favorite"); // 배열의 크기만큼 루프를 돌면서 값을 출력함. for(int i=0; i<favorites.length;i++){ out.println(favorites[i]+"<br>"); } %> </td> </tr> </table> </body> </html>
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/306 관련글 쓰기

Top

자바 웹 프로그래밍 <5장 심화연습문제> 3번

<5장 심화연습문제> 3번

3. 다음과 같은 자바 소스 구조를 exam5-1.jsp로 변환해 실행해보라.

public class MyClass {
	int num1 = 20;
	int num2 = 50;
	public int sum() {
		return num1 + num2;
	}
}




요구사항 : 다음JSP 구문을 통해 결과를 화면에서 확인할 수 있도록 한다.
실행결과 : <%=sum() %>


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %>

<%!

	// 멤버 변수 선언
	int num1 = 20;
	int num2 = 50;

	//연산자 처리를 위한 메소드
	public int sum(){
		return num1 + num2;
	}

%>

<html>
<head>
<title>exam5-1.jsp</title>
</head>
<body>

실행결과 : <%=sum() %>

</body>
</html>

사용자 삽입 이미지
Comment 0 Trackback 0

Trackback : http://my.silpir.net/trackback/305 관련글 쓰기

Top

prev 1 2 3 next