2009년 6월 30일 화요일
2009년 6월 29일 월요일
filter 를 이용한 한글처리
--web.xml-------------------------------------------------------------------------
<web-app>
<filter>
<filter-name>encoder</filter-name>
<filter-class>utils.hangle.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>euc-kr</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoder</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
</web-app>
--EncodingFilter.java---------------------------------------------------------------
package utils.hangle;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* EncodingFilter.java
* @web:filter
* name = "encoder"
* @web:filter-init-param
* name = "encoding"
* value = "euc-kr"
* @web:filter-mapping
* url-pattern = "*.jsp"
*/
public class EncodingFilter implements Filter {
private static Log log = LogFactory.getLog(EncodingFilter.class);
private boolean enabled = true;
private String encoding;
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(final FilterConfig config) throws ServletException {
this.encoding = config.getInitParameter("encoding");
if (log.isInfoEnabled()) {
log.info("Encoding filter has been initialized : " + encoding);
}
}
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(
final ServletRequest request,
final ServletResponse response,
final FilterChain chain) throws IOException, ServletException {
if (enabled && (encoding != null)) {
try {
request.setCharacterEncoding(encoding);
} catch (UnsupportedEncodingException e) {
if (log.isWarnEnabled()) {
log.warn("Encoding filter has been disabled.", e);
}
this.enabled = false;
}
}
chain.doFilter(request, response);
}
/**
* @see javax.servlet.Filter#destroy()
*/
public void destroy() {
if (log.isInfoEnabled()) {
log.info("Encoding filter has been destoryed.");
}
}
}
최단거리(미완성)
Djikstra's algorithm (named after its discover, E.W. Dijkstra) solves the problem of finding the shortest path from a point in a graph (the source) to a destination. It turns out that one can find the shortest paths from a given source to all points in a graph in the same time, hence this problem is sometimes called the single-source shortest paths problem.
Othello (미완성)
이미지 스핀....
mid 파일 간단 실행 예제...
InputStreamReader 이용 DOS 창에서 입력
java.util.Random
import java.util.Scanner;
파일입출력-일본어
접근지정자
actionform,controller를 이용한 한글처리
--RequestProcessor 클래스를 오버라이딩 하는법------------------------------
파일다운시 붙는 숫자 제거
// subject는 파일이름
// replace() 파일을 받을시 '.'이 [].으로 변경을 방지..
public String replace(String subject)
{
String replaced="";
int index=0;
StringBuffer st=new StringBuffer();
index=subject.lastlndexof(".");
replaced=new String(subject.substring(0,index));
// ['.' => UTF-8 code=> 2e ]앞에 % escape문자를 붙인것
replaced=replaced.repalaceAll("\\.","%2e");
sf.append(replaced);
sf.append(subject.subSequence(index.subject.length()));
return.st.toString();
}
2009년 6월 28일 일요일
Spring 문서
정규식 (예)
/^[a-z0-9_+.-]+@([a-z0-9-]+\.)+[a-z0-9]{2,4}$/
URL:
/^(file|gopher|news|nntp|telnet|https?|ftps?|sftp):\/\/([a-z0-9-]+\.)+[a-z0-9]{2,4}.*$/
HTML 태그 - HTML tags:
/\<(/?[^\>]+)\>/
전화 번호 - 예, 123-123-2344 혹은 123-1234-1234:
/(\d{3}).*(\d{3}).*(\d{4})/
날짜 - 예, 3/28/2007 혹은 3/28/07:
/^\d{1,2}\/\d{1,2}\/\d{2,4}$/
jpg, gif 또는 png 확장자를 가진 그림 파일명:
/([^\s]+(?=\.(jpg|gif|png))\.\2)/
1부터 50 사이의 번호 - 1과 50 포함:
/^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$/
16 진수로 된 색깔 번호:
/#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?/
적어도 소문자 하나, 대문자 하나, 숫자 하나가 포함되어 있는 문자열(8글자 이상 15글자 이하) - 올바른 암호 형식을 확인할 때 사용될 수 있음:
/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}/
Define foreign key
Drop table Authors;
Drop table AuthorBook;
CREATE TABLE Books (
BookID SMALLINT NOT NULL PRIMARY KEY,
BookTitle VARCHAR(60) NOT NULL,
Copyright YEAR NOT NULL
)
ENGINE=INNODB;
INSERT INTO Books VALUES (1, 'Letters', 1934),
(2, 'Ohio', 1919),
(3, 'Angels', 1966),
(4, 'Speaks', 1932),
(5, 'Man', 1996),
(6, 'A', 1980),
(7, 'Card', 1992),
(8, 'The', 1993);
CREATE TABLE Authors (
AuthID SMALLINT NOT NULL PRIMARY KEY,
AuthFN VARCHAR(20),
AuthMN VARCHAR(20),
AuthLN VARCHAR(20)
)
ENGINE=INNODB;
INSERT INTO Authors VALUES (1, 'Henry', 'S.', 'Thompson'),
(2, 'Jack', 'Carol', 'Oates'),
(3, 'Red', NULL, 'Elk'),
(4, 'White', 'Maria', 'Rilke'),
(5, 'Anne', 'Kennedy', 'Toole'),
(6, 'Jane', 'G.', 'Neihardt'),
(7, 'Jane', NULL, 'Yin'),
(8, 'Alan', NULL, 'Wang');
CREATE TABLE AuthorBook (
AuthID SMALLINT NOT NULL,
BookID SMALLINT NOT NULL,
PRIMARY KEY (AuthID, BookID),
FOREIGN KEY (AuthID) REFERENCES Authors (AuthID),
FOREIGN KEY (BookID) REFERENCES Books (BookID)
)
ENGINE=INNODB;
INSERT INTO AuthorBook VALUES (1, 8),
(2, 7),
(3, 6),
(4, 5),
(5, 4),
(6, 2),
(8, 1);
입력상자에서 자리수 차면 이동하기
<SCRIPT language=JavaScript>
function Nextchk(arg,len,nextname) {
if (arg.value.length==len) {
nextname.focus() ;
return;
}
}
</SCRIPT>
<FORM method=post name=zipcode>
우편번호<INPUT maxLength=3 name=zip1 size=3
onkeyup='Nextchk(this,3,document.zipcode.zip2)'>
-
<INPUT maxLength=3 name=zip2 size=3>
</FORM>
자식창 ==(post)==> 부모창
(자식창)
<form name="frm" method="post" action="./test.jsp" target="pwin"> ......... </form> <script> document.frm.submit(); self.close(); </script> (부모창) <script> window.name = "pwin"; </script>
긴 문자열 짧게 보여주기
div 내용 프린트하기
from http://mkwilson.tistory.com/entry/특정-div-프린트-하기
function
content_print(){
var initBody =
document.body.innerHTML;
window.onbeforeprint =
function(){
document.body.innerHTML =
document.getElementById('선택될 div id').innerHTML;
}
window.onafterprint = function(){
document.body.innerHTML = initBody;
}
window.print();
}
</script>
===============================================================================================
<div id='content'>
내용 content_1
</div>
<div id='content_2'>
내용 content_2
</div>
<input
type="button" value="print"
onclick="javascript:content_print();">
================================================================================================
선택될 div id 이부분에 div id 를 삽입하면 된다.
print 버튼을 누르면 지정된 div 안의 내용이 프린트
된다.
복수 모듈 선언
/WEB-INF/web.xml (1)
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts/struts-default.xml</param-value>
</init-param>
<init-param>
<param-name>config/user</param-name>
<param-value>/WEB-INF/struts/struts-user.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
/WEB-INF/web.xml (2) http://localhost/action.do http://localhost/user/action.do
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/user</param-name>
<param-value>/WEB-INF/struts-config-user.xml</param-value>
</init-param>
/WEB-INF/struts/struts-user.xml
<?xml version="1.0" encoding="euc-kr" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
</struts-config>