1 / 12

강의 보조자료 & Homework #2 - 로그인과 이미지 카운터 만들기 -

강의 보조자료 & Homework #2 - 로그인과 이미지 카운터 만들기 -. Internet Computing Laboratory @ KUT Youn-Hee Han. [ 보조자료 1-1] Scope. <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <html> <head><title>scope</title></head> <body> <%

conor
Télécharger la présentation

강의 보조자료 & Homework #2 - 로그인과 이미지 카운터 만들기 -

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 강의 보조자료 & Homework #2- 로그인과이미지 카운터 만들기 - Internet Computing Laboratory @ KUT Youn-Hee Han

  2. [보조자료 1-1] Scope <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <html> <head><title>scope</title></head> <body> <% String p1 = request.getParameter("p1"); String p2 = request.getParameter("p2"); String value1 = null; String value2 = null; if (p1 != null && p2 != null) { pageContext.setAttribute("parameter-1", p1); pageContext.setAttribute("parameter-2", p2); } value1 = (String)pageContext.getAttribute("parameter-1"); value2 = (String)pageContext.getAttribute("parameter-2"); out.println("<BR>" + value1 + " = " + value2); %> </body> </html> • Scope에 관한 예제 scope1.jsp 빨간색으로 되어진 부분을 request, session, application으로 바꾸어 실행한 결과는? Web Programming

  3. [보조자료 1-2] Scope <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <html> <head><title>scope</title></head> <body> <% value1 = (String)pageContext.getAttribute("parameter-1"); value2 = (String)pageContext.getAttribute("parameter-2"); out.println("<BR>" + value1 + " = " + value2); %> </body> </html> scope2.jsp Web Programming

  4. [보조자료 2] 스트링 숫자, 객체 숫자, 숫자 • String Number  Primitive Number String numS1 = “45” // String numS1 = new String(“45”); int num1 = Interger.parseInt(numS1); String numS2 = “45.12” double num2 = Double.parseDouble(numS2); Float num3 = Float.parseFloat(numS2); • Object Number  Primitive Number Integer numO1 = new Integer(100); //Integer numO1 = new Integer(“100”); int num1 = numO1.intValue(); Double numO2 = new Double(100.334); //Double numO2 = new Double(“100.34”); double num2 = numO2.doubleValue(); float num3 = numO2.floatValue(); Web Programming

  5. [보조자료 3-1] 읽기, 쓰기 • 자바에서 전형적인 Reading 방법 is 파일 InputStream is = application.getResouceAsStream(path); new BufferedReader(new InputStreamReader(is)); 단순 파일(realReadPath) new BufferedReader(new FileReader(realReadPath)); Web Programming

  6. [보조자료 3-2] 읽기, 쓰기 • URL과 Stream 예제 <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <%@ page import = "java.net.*" %> <html> <head><title>application 기본 객체 사용하여 자원 읽기</title></head> <body> <% BufferedReader br2 = null; String line = null; try { br2 = new BufferedReader(new InputStreamReader( new URL("http://www.yahoo.co.kr").openStream()) ); while ((line = br2.readLine()) != null) { out.print(line); } } catch(IOException ex) { out.println("예외 발생: " + ex.getMessage()); } finally { if (br2 != null) try { br2.close(); } catch(IOException ex) {} } %> </body> </html> Web Programming

  7. 로그인 처리를 위한 web.xml 구성 <?xml version="1.0" encoding="euc-kr"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>나의 홈페이지</display-name> <description>웹 프로그래밍 수업시간에 활용하는 나의 홈페이지</description> <context-param> <description>로그인 아이디</description> <param-name>loginID</param-name> <param-value>(자신이 스스로 정함)</param-value> </context-param> <context-param> <description>로그인 패스워드</description> <param-name>passwd</param-name> <param-value>(자신이 스스로 정함)</param-value> </context-param> <context-param> <description>로그인 이름</description> <param-name>name</param-name> <param-value>(자신의 이름)</param-value> </context-param> </web-app> • 자신의 웹 루트에서 WEB-INF 디렉토리에 다음과 같은 web.xml 구성 Web Programming

  8. 간단한 로그인 처리 • 다음과 같은 기능을 지닌 index.jsp 구성 반갑습니다. 한연희님! 오늘도 좋은 하루 되세요. • 앞에서 web.xml 내에 설정한 아이디와 패스워드와 비교를 하여 처리 • index.jsp 페이지 하나에서 모두 처리 Web Programming

  9. 단순 파일 읽기/쓰기 <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <html> <head><title>File 쓰기 & String ==> int</title></head> <body> <% String readResourcePath = "/message/notice/number.txt"; String writeResourcePath = "/message/notice/number.txt"; String realReadPath = application.getRealPath(readResourcePath); String realWritePath = application.getRealPath(writeResourcePath); BufferedReader br = null; PrintWriter pr = null; try { br = new BufferedReader(new FileReader(realReadPath)); String numS = br.readLine(); br.close(); out.println(numS); pr = new PrintWriter (new FileWriter(realWritePath)); int num = Integer.parseInt(numS); pr.println(num+1); pr.close(); } catch(IOException ex) { out.println("예외 발생: " + ex.getMessage()); } %> </body> </html> Web Programming

  10. 세션의 타임아웃 설정 및 isNew() 함수 사용 <%@ page contentType = "text/html; charset=euc-kr" %> <%@ page import = "java.io.*" %> <html> <head><title>isNew</title></head> <body> <% out.println(session.getMaxInactiveInterval() + "<BR/><BR/>"); //default=1800sec. if (session.isNew()) out.println("세션이 처음 생성되었습니다."); else out.println("이미 생성된 세션이 있습니다."); session.setMaxInactiveInterval(10); //changed to 10sec. %> </body> </html> • 적절한 InactiveInterval 값을 설정하고, 해당 시간 동안 Reload를 해도 카운터의 숫자는 증가하지 말아야 한다. Web Programming

  11. 실시간에 이미지 파일 정하기 <% for (int j = 0; j < numS.trim().length(); j++) { %> <img src=“/images/number<%= numS.charAt(j) %>.jpg" border=0> <% } %> • 위 코드를 수행하기 전에 0, 1, 3, 4, 5, 6, 7, 8, 9에 해당하는 숫자 이미지를 웹에서 구한다. • 각각의 숫자 이미지는 자신의 웹 루트 디렉토리 밑의 하위 디렉토리로서 images 를 만들고 그곳에 number0.jpg (or gif), number1.jpg, number2.jpg, …, number9.jpg 로 저장한다. Web Programming

  12. Homework #2 요구사항 • 자신의 웹 루트로 접속하면 간단한 자기 소개를 하는 페이지를 만든다. • index.jsp • 로그인 부분을 삽입한다. • 이미지 카운터를 적절한 위치에 삽입한다. • 이전 Homework #1에서 구성한 회원가입 메뉴를 로그인 화면 바로 아래에 링크를 달아 연결한다. • (Option) 자기 소개 메인 화면 및 회원가입 메뉴를 좀 더 보기 좋게 가다듬는다. • 회원가입 메뉴의 한글화… • Due Date: 4월 26일 (목) 23:59:59 Web Programming

More Related