# 자세한 설명이 되어있는 좋은 사이트
http://sial.org/howto/perl/one-liner/#s2

# 기본기 잡기 위해서는 한번쯤 보면 좋은 사이트
http://www.unixguide.net/unix/perl_oneliners.shtml

# 유투브 동영상 Perl One-liner로 다운 받는 방법
http://www.catonmat.net/blog/downloading-youtube-videos-with-a-perl-one-liner/

# Perl One-liner는 아니지만 유용한 책을 소개
http://aero.sarang.net/blog/2009/03/-perl-4.html

# Perl One-liner 을 배우기전에 꼭 한번 봤으면 하는 자료
http://gypark.pe.kr/wiki/Perl/%EC%A0%95%EA%B7%9C%ED%91%9C%ED%98%84%EC%8B%9D

# Perl을 배우기 위해서 이정도 문서는 읽어줘야 하지 않을 까요?^^
http://doc.perl.kr/twiki/bin/view/Wiki/HowToStartPerl#시작하기
지금은 다른 언어를 활용하여 경험을 쌓고 있지만 언젠가는 Perl의 발전이 한국에도 찾아오길 바란다.
수많은 Cpan을 자랑으로 OOP 언어라는 인식하기를....


Perl그리고grep한다 지정한 문자열을 포함한 행을 추출

관련

grep(을)를 실현한다원 라이너(커멘드 prompt(으)로부터 사용한다)

perl -ne "print if ( /search/ )" inputfile.txt > outputfile.txt

inputfile.txt
search1
kjhkh
search2
lkjlkjl
oiuyyiu
search3

원 라이너란

-e

  • -e(을)를 지정하면, 그 후에 계속 된다Perl스크립트가 직접 실행된다.

-n

  • -n(을)를 지정하면, 그 후에 계속 된다Perl스크립트가,while(<>){ }그리고 둘러싸인 것이 된다.

원 라이너 해설

  • perl -ne "print if( /search/ )" inputfile.txt > outputfile.txt
  • 이 문장은 이하의,1,2 (와)과 같다.

1: grep.pl

while(<>){ # ←인수로 주어진 파일의 각 행이,<>에게 건네진다.
           #   <>그리고 받은 각 행은, 루프 속에서,$_에게 건네진다.
    print if( /search/ ); # ←정규 표현//에는,$_하지만 암묵적으로 이용된다
                          #   print의 인수에는, 암묵적으로$_하지만 이용된다. 
}

2: 실행

perl grep.pl inputfile.txt > outputfile.txt


Windows커멘드 prompt그리고cat한다

 커멘드 prompt로cat( 파일의 결합 )(을)를 하려면 이하와 같이 합니다.

perl -ne "print" file1 file2 file3 > output.txt





저작자 표시
Posted by CalmMass


1. 리스너
리스너란 ?

  • 리스너는 특정 상황을 모니터링 하다가 해당 상황이 발생하면 동작하는 일종의 서블릿 으로 웹 애플리케이션 시작 및 운영 종료 과정에서 발생하는 일련의 과정에서 특정 상황에 필요한 작업을 처리하기 위해 사용 한다



web.xml 설정 방법

  <listener>
   <listener-class>bit.web.listener.TestContextListener</listener-class>
  </listener>


소스 예제

 

package bit.web.beans;

public class Book {

 private String title;
 private String author;
 private int price;
 private String publisher;
 public Book(String title, String author, int price, String publisher) {

  this.title = title;
  this.author = author;
  this.price = price;
  this.publisher = publisher;
 }
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public String getAuthor() {
  return author;
 }
 public void setAuthor(String author) {
  this.author = author;
 }
 public int getPrice() {
  return price;
 }
 public void setPrice(int price) {
  this.price = price;
 }
 public String getPublisher() {
  return publisher;
 }
 public void setPublisher(String publisher) {
  this.publisher = publisher;
 }
 
 
 
}


 
package bit.web.listener;

import javax.servlet.*;
import bit.web.beans.Book;

// ServletContextListener 인터페이스를 구현한 클래스
public class TestContextListener implements ServletContextListener {
 
 public void contextDestroyed(ServletContextEvent arg0){
  System.out.println("TestContextListener 종료 되었습니다.");
 }
 
 // 애플리케이션 시작시 호출되는 리스너 클래스 메서드로 Book 클래스 객체 생성
 public void contextInitialized(ServletContextEvent arg0){
  ServletContext ctx = arg0.getServletContext();
  Book mybook = new Book("넛지","캐스 R", 200000, "리더스북");
  ctx.setAttribute("book",mybook);
  System.out.println("TestContextListener 초기화 되었습니다.");
 }
}


 

<%@ page language="java" contentType="text/html; charset=euc-kr"
 pageEncoding="euc-kr"%>
<html>
<head>
<mata http-equiv="Content-type" content="text/html; charset=euc-kr"></mata>
<title>ListenerTest.jsp</title>
</head>
<body>
 <center>
 <H2>리스너 테스트</H2>
 <HR />
 도서명 : ${book.title} <br />
 저자명 : ${book.author} <br />
 가격 : ${book.price} <br />
 출판사 : ${book.publisher} <br />
 
 
 </center>
</body>
</html> 



2. 서블릿 필터

서블릿 필터란?
  • 리스너와 함께 대표적인 특별한 형태의 서블릿
  • 사용자 요청에 따라 특정 서블릿이나 JSP가 실행되기전 사전 작업 수행
  • 여러 개의 서블릿을 다양한 조건으로 설정해 하나의 요청에 여러 필터가 사전에 수행 될 수 있도록 할 수 있음


[ 서블릿 필터구조 ]

 

web.xml 설정 방법
  <filter>
   <filter-name>EncFilter</filter-name>
   <filter-class>bit.web.filter.EncFilter</filter-class>
   <init-param>
    <param-name>encoding</param-name>
    <param-value>euc-kr</param-value>
   </init-param>
  </filter>
 
  <filter-mapping>
   <filter-name>EncFilter</filter-name>
   <url-pattern>*.jsp</url-pattern>
  </filter-mapping>


소스예제

 
package bit.web.filter;

import java.io.*;
import javax.servlet.*;


public class EncFilter implements Filter {
 private FilterConfig filterConfig = null;
 private String encoding = null;
 
 public void destroy(){
  filterConfig = null;
 }
 
 public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
  throws IOException, ServletException{
  if(arg0.getCharacterEncoding() == null){
   arg0.setCharacterEncoding(encoding);
   arg2.doFilter(arg0, arg1);
  }
 }
 
 public void init(FilterConfig arg0) throws ServletException{
  this.filterConfig = arg0;
  this.encoding = filterConfig.getInitParameter("encoding");
 }
}


<!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>EncForm</title>
</head>
<body>
 <H2>EncForm.html</H2>
 <HR />
 <form method="post" action="result.jsp">
  <input type="text" name="title">
  <input type="submit" name="확인">
 </form>
</body>
</html> 

 

<%@ page language="java" contentType="text/html; charset=euc-kr"
 pageEncoding="euc-kr"%>
<html>
<head>
<mata http-equiv="Content-type" content="text/html; charset=euc-kr"></mata>
<title>result.jsp</title>
</head>
<body>
 <center>
 <HR />
 처리결과 : ${param.title}
 
 </center>

</body>

</html>



저작자 표시
Posted by CalmMass


라이브러리 다운로드
http://java.sun.com/products/jsp/jstl/
Downloads

1.2 - Maintenance Release
Specification Download

위와 같이 받는 방법도 있고 아래처럼 아예 다운로드를 원하는 것만 받아도 된다.
http://jakarta.apache.org/site/downloads/downloads_taglibs.html
http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi
1.1.2.zip


war 파일을 D:\apache-tomcat-6.0.20\webapps 로 옮긴다.
압축을 풀고 아래 있는 2개의 파일을
standard-examples.war, standard-doc.war   ->>>>
D:\apache-tomcat-6.0.20\webapps
자신이 설치한 톰켓 서버로 옮긴다.

톰켓을 시작 하면 자동으로 파일이 생성 된다.


jakarta-taglibs-standard-1.1.2\lib jar 파일 2개를 모두 프로젝트로 설정한 lib 폴더/디렉토리로 옮기면 된다.


JSTL core 예제 - set, out, remove

 
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
<title> JSTL core 예제 - set, out, remove</title>
</head>
<body>
browser 변수 값 설정
<c:set var="browser" value="${header['User-Agent']}" scope="request"/> <br />
browser = <c:out value="${browser}" /><br />
단순 el 표현식 browser = :${browser}<br />

browser = <%= request.getAttribute("browser").toString() %><br />

brower변수 값 제거 후 <br />
<c:remove var="browser" /><br />
browser = <c:out value="${browser}" />
</body>
</html>


결과

browser 변수 값 설정
browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 1.1.4322)
단순 el 표현식 browser = :Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 1.1.4322)
browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 1.1.4322)
brower변수 값 제거 후

browser =

 



JSTL core 예제 - if, choose, when, otherwise


<%@ page contentType = "text/html; charset=euc-kr" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>JSTL core 예제 - if, choose, when, otherwise</title>
</head>
<body>
<c:set var="country" value="${'Korea'}"/>
<c:if test="${country != null}">
  국가명: <c:out value="${country}"/>
</c:if>
<p>

<c:choose>
  <c:when test="${country == 'Korea'}">
     <c:out value="${country}"/>의 겨울은 춥다.
  </c:when>
  <c:when test="${country == 'Canada'}">
     <c:out value="${country}"/>의 겨울은 너무 춥다.
  </c:when>
  <c:otherwise>
     그외의 나라들의 겨울은 알 수 없다.
  </c:otherwise>
</c:choose>
</body>
</html>
 

결과

국가명: Korea

Korea의 겨울은 춥다.



 



JSTL core 예제 - forEach

 <%@ page contentType = "text/html; charset=euc-kr" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL core 예제 - forEach</title>
</head>
<body>
<h3>Header 정보:</h3>

<c:forEach var="head" items="${headerValues}">
  param: <c:out value="${head.key}"/><br>
  values:
   <c:forEach var="val" items="${head.value}">
     <c:out value="${val}"/>
   </c:forEach>
   <p>
</c:forEach>

</body>
</html>


결과

param: cookie
values: JSESSIONID=6500B36DF6843A22DA3DE8ABB2FB1F1F

param: connection
values: Keep-Alive

param: host
values: localhost:9090

param: accept-language
values: ko

param: accept
values: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*

param: user-agent
values: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 1.1.4322)

param: accept-encoding
values: gzip, deflate


 




저작자 표시
Posted by CalmMass
TAG Java, JSP