-array copy
var clone = myArray.slice(0);
-array delete
.splice(0);
삭제: .pop();, 추가: .push(var);
지정삭제
arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
2015년 1월 21일 수요일
java list -> javascript array
var rouletteArr = new Array(); //["기프티콘","마일리지 500점","마일리지 100점","기프티콘","마일리지 2,000점","마일리지 50점"];
<c:forEach items="${resultList}" var="item">
rouletteArr.push("${item.rouletteSeq}");
</c:forEach>
vo List 일때는 이렇게
var dataList = new Array();
var dataObj = new Object();
var categoryName = "";
<c:forEach items="${resultList}" var="result">
categoryName = "${result.categoryName}";
dataObj[categoryName] = new Object();
dataObj[categoryName].categoryName = "${result.categoryName}";
dataObj[categoryName].weekStartDt = "${result.weekStartDt}";
dataObj[categoryName].weekEndDt = "${result.weekEndDt}";
dataObj[categoryName].sessionAll = "${result.sessionAll}";
dataObj[categoryName].sessionDistinct = "${result.sessionDistinct}";
dataObj[categoryName].loginAll = "${result.loginAll}";
dataObj[categoryName].loginDistinct = "${result.loginDistinct}";
dataList.push(dataObj[categoryName]);
</c:forEach>
사용할때는 이렇게
$.each(dataList, function(index){
categoryStr += "<category name='"+ this.weekStartDt + " - " + (this.weekEndDt).substring(5) + "' /> \n";
});
forEach문으로 루프 돌려서 Array 오브젝트에 넣어주면 됨.
[출처] java List to javascript Array , java vo list to javascript array list |작성자 키키
http://hongy0225.blog.me/220183635327
<c:forEach items="${resultList}" var="item">
rouletteArr.push("${item.rouletteSeq}");
</c:forEach>
vo List 일때는 이렇게
var dataList = new Array();
var dataObj = new Object();
var categoryName = "";
<c:forEach items="${resultList}" var="result">
categoryName = "${result.categoryName}";
dataObj[categoryName] = new Object();
dataObj[categoryName].categoryName = "${result.categoryName}";
dataObj[categoryName].weekStartDt = "${result.weekStartDt}";
dataObj[categoryName].weekEndDt = "${result.weekEndDt}";
dataObj[categoryName].sessionAll = "${result.sessionAll}";
dataObj[categoryName].sessionDistinct = "${result.sessionDistinct}";
dataObj[categoryName].loginAll = "${result.loginAll}";
dataObj[categoryName].loginDistinct = "${result.loginDistinct}";
dataList.push(dataObj[categoryName]);
</c:forEach>
사용할때는 이렇게
$.each(dataList, function(index){
categoryStr += "<category name='"+ this.weekStartDt + " - " + (this.weekEndDt).substring(5) + "' /> \n";
});
forEach문으로 루프 돌려서 Array 오브젝트에 넣어주면 됨.
[출처] java List to javascript Array , java vo list to javascript array list |작성자 키키
http://hongy0225.blog.me/220183635327
2015년 1월 20일 화요일
input , select 크기 맞추기
A solution?
Then we discovered this:
.form-text {
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
Combining the two sets of CSS above results in form elements that look like this:
Depending on your choice of browser, there’s a good chance the two elements above are now the same width.
What is the “box-sizing” property?
An explanation of the “box-sizing” property from the W3Schools website is as follows:
“The box-sizing property allows you to define certain elements to fit an area in a certain way. For example, if you’d like two bordered boxes side by side, it can be achieved through setting box-sizing to ‘border-box’. This forces the browser to render the box with the specified width and height, and place the border and padding inside the box.”
This “fix” appears to work in Internet Explorer 8 and above, Firefox, Safari and Chrome. Without it, we could never find a way of making the elements the same width even with specific width, padding, margin and border properties.
input, textarea 적용
Then we discovered this:
.form-text {
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
Combining the two sets of CSS above results in form elements that look like this:
Depending on your choice of browser, there’s a good chance the two elements above are now the same width.
What is the “box-sizing” property?
An explanation of the “box-sizing” property from the W3Schools website is as follows:
“The box-sizing property allows you to define certain elements to fit an area in a certain way. For example, if you’d like two bordered boxes side by side, it can be achieved through setting box-sizing to ‘border-box’. This forces the browser to render the box with the specified width and height, and place the border and padding inside the box.”
This “fix” appears to work in Internet Explorer 8 and above, Firefox, Safari and Chrome. Without it, we could never find a way of making the elements the same width even with specific width, padding, margin and border properties.
input, textarea 적용
2014년 12월 25일 목요일
div 정중앙 배치
// DIV 정중앙 배치
.center{
width: 200px;
height: 200px;
background-color: black;
position:absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.center{
width: 200px;
height: 200px;
background-color: black;
position:absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
2014년 12월 10일 수요일
HttpURLConnection
- URL 내용을 읽어오거나, URL 주소에 GET / POST로 데이터를 전달 할 때 사용함
- 웹 페이지나 서블릿에 데이터를 전달 수 있음
- URL --> openConnection() --> URLConnection --> getInputStream --> InputStream (내용읽음)
- URL 의 OpenStream() : URL의 입력 스트림만 개설 (차이점)
- URLConnection : URL의 입력, 출력 스트림 개설
Construct
protected URLConnection(URL) : 직접 생성 불가능 , OpenConnection으로 연결함
Method
addRequestProperty(String a, String b) : 키(a) 와 값(b)을 가지고 요청할 수 있는
Properity 값을 미리 설정해 놓음. 특정 키값을 가지고 읽을 수 있도록 함
connect() : 연결 된 곳에 접속 할때 (connect() 호출해야 실제 통신 가능함)
getAllowUserInteraction() : 연결 된 곳에 사용자가 서버와 통신 할 수 있는 환경 확인(boolean)
in/output이 해당 서버 , 연결 포트로 가능한지 확인함
getContent() : content 값을 리턴 받음 (inputStream 값을 리턴 함)
getContent(Class[]) : 위 내용을 class[] 배열 값을 입력함
getContentEncoding() : 인코딩 타입을 String으로 리턴함
getContentLength() : content 길이 (-1 이면 정상적으로 값이 넘어오지 않았음)
getContentType() : content 가 http로 되어 있는지 타입 (ex: http-type )
getDate() : content의 날짜 (new Date(~~) 으로 변환해 줘야 함 / Long 리턴)
getDefaultAllowUserInteraction(): 기본적으로 User와 통신 가능한 상태인지 (boolean)
getDefaultUserCaches() : cache를 사용할 것 인지 (boolean)
getDoInput() : Server에서 온 데이터를 입력 받을 수 있는 상태인지 (본인 상태-default : true)
getDoOutput() : Server에서 온 데이터를 출력 할수 있는 상태인지
(Client 상태 -default : false)
getExpiration() : 유효 기간
getFileNameMap() : File Name Map
getHeaderField(int) : Head Field 값 받아옴 (http Head 값)
getHeaderFiled(String) :
getLastModified() : 마지막 수정 시간
getInputStream() : InputStrema 값을 뽑아냄
getOutputStream() : OutputStream 값을 뽑아냄
setDoInput(boolean) : Server 통신에서 입력 가능한 상태로 만듬
setDoOutput(boolean) : Server 통신에서 출력 가능한 상태로 만듬
- Server와 통신을 하고자 할때는 반드시 위 두 method를 true로 해 놔야 함
----------------------------------------------------------------------------------------------------------------------------------
- 웹 페이지나 서블릿에 데이터를 전달 수 있음
- URL --> openConnection() --> URLConnection --> getInputStream --> InputStream (내용읽음)
- URL 의 OpenStream() : URL의 입력 스트림만 개설 (차이점)
- URLConnection : URL의 입력, 출력 스트림 개설
Construct
protected URLConnection(URL) : 직접 생성 불가능 , OpenConnection으로 연결함
Method
addRequestProperty(String a, String b) : 키(a) 와 값(b)을 가지고 요청할 수 있는
Properity 값을 미리 설정해 놓음. 특정 키값을 가지고 읽을 수 있도록 함
connect() : 연결 된 곳에 접속 할때 (connect() 호출해야 실제 통신 가능함)
getAllowUserInteraction() : 연결 된 곳에 사용자가 서버와 통신 할 수 있는 환경 확인(boolean)
in/output이 해당 서버 , 연결 포트로 가능한지 확인함
getContent() : content 값을 리턴 받음 (inputStream 값을 리턴 함)
getContent(Class[]) : 위 내용을 class[] 배열 값을 입력함
getContentEncoding() : 인코딩 타입을 String으로 리턴함
getContentLength() : content 길이 (-1 이면 정상적으로 값이 넘어오지 않았음)
getContentType() : content 가 http로 되어 있는지 타입 (ex: http-type )
getDate() : content의 날짜 (new Date(~~) 으로 변환해 줘야 함 / Long 리턴)
getDefaultAllowUserInteraction(): 기본적으로 User와 통신 가능한 상태인지 (boolean)
getDefaultUserCaches() : cache를 사용할 것 인지 (boolean)
getDoInput() : Server에서 온 데이터를 입력 받을 수 있는 상태인지 (본인 상태-default : true)
getDoOutput() : Server에서 온 데이터를 출력 할수 있는 상태인지
(Client 상태 -default : false)
getExpiration() : 유효 기간
getFileNameMap() : File Name Map
getHeaderField(int) : Head Field 값 받아옴 (http Head 값)
getHeaderFiled(String) :
getLastModified() : 마지막 수정 시간
getInputStream() : InputStrema 값을 뽑아냄
getOutputStream() : OutputStream 값을 뽑아냄
setDoInput(boolean) : Server 통신에서 입력 가능한 상태로 만듬
setDoOutput(boolean) : Server 통신에서 출력 가능한 상태로 만듬
- Server와 통신을 하고자 할때는 반드시 위 두 method를 true로 해 놔야 함
----------------------------------------------------------------------------------------------------------------------------------
URL url = new URL("주소");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
// 서버로부터 메세지를 받을 수 있도록 한다. 기본값은 true이다.
con.setDoInput(true);
// 헤더값을 설정한다.
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// 전달 방식을 설정한다. POST or GET, 기본값은 GET 이다.
con.setRequestMethod(method);
// 서버로 데이터를 전송할 수 있도록 한다. GET방식이면 사용될 일이 없으나, true로 설정하면 자동으로 POST로 설정된다. 기본값은 false이다.
con.setDoOutput(true);
// POST방식이면 서버에 별도의 파라메터값을 넘겨주어야 한다.
String paramstr = buildParameters(params);
OutputStream out = con.getOutputStream();
out.write( paramstr.getBytes("UTF-8") );
out.flush();
out.close();
// con.getResponseCode();
// 결과값을 가져온다.
InputStream in = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
try
{
in = con.getInputStream();
while(true)
{
int readlen = in.read(buf);
if( readlen < 1 )
break;
bos.write(buf, 0, readlen);
}
String output = new String(bos.toByteArray(), "UTF-8");
System.out.println(output);
}catch (Exception e){
e.printStackTrace();
}finally{
if(bos != null) try{bos.close();}catch(IOException aa){}
if(in != null) try{bos.close();}catch(IOException aa){}
}
호출후에는 응답을 꼭 받아야한다.
con.getResponseCode();
그렇지 않으면 연결자체를 하지 않는다.
in = con.getInputStream();
in.close();
이렇게 InputStream을 가져와도 호출이 가능하다.
즉, 요청후에는 getResponseCode()를 호출하거나 InputStream()을 얻어야 정상적으로 연결이 이루어진다.
아래는 POST로 파라메터값을 보낼때 유용한 메소드입니다.
rath님의 me2day라이브러리를 참조했습니다.
private String buildParameters( Map params ) throws IOException
{
StringBuilder sb = new StringBuilder();
for(Iterator i= params.keySet().iterator(); i.hasNext(); )
{
String key = (String)i.next();
sb.append( key );
sb.append( "=" );
sb.append( URLEncoder.encode((String)params.get(key), "UTF-8") );
if( i.hasNext() )
sb.append( "&" );
}
return sb.toString();
}
2014년 12월 1일 월요일
javascript 날짜차이구하기
Date 개체
Date개체는 날짜를 표현하는 개체로 1970년 1월 1일을 기준으로 Milliseconds 값으로 날짜를 표현합니다. 즉 Milliseconds값을 지정하여 Date개체를 생성할 수 도 있고, 또 두 Date를 빼면 Milliseconds 값으로 반환합니다.
자세히 말해서 Date개체는 1970년 1월 1일 전후로 285,616년(±100,000,000 Milliseconds)까지 표현합니다.
날짜의 차이 구하기
Date개체의 특성을 바탕으로 날짜의 차이는 아래와 같이 직접 계산을 통해 쉽게 구하실 수 있습니다.
var firstDate = new Date(2010, 10, 1);
var secodDate = new Date(2010, 12, 31);
var diffMilSec = firstDate - secodDate;
var diffSec = diffMilSec / 1000;
var diffMin = diffSec / 60;
var diffHour = diffMin / 60;
var diffDay = diffHour / 24;
function getDiffDays(first, second)
{
return (second-first)/(1000*60*60*24)
}
Date개체는 날짜를 표현하는 개체로 1970년 1월 1일을 기준으로 Milliseconds 값으로 날짜를 표현합니다. 즉 Milliseconds값을 지정하여 Date개체를 생성할 수 도 있고, 또 두 Date를 빼면 Milliseconds 값으로 반환합니다.
자세히 말해서 Date개체는 1970년 1월 1일 전후로 285,616년(±100,000,000 Milliseconds)까지 표현합니다.
날짜의 차이 구하기
Date개체의 특성을 바탕으로 날짜의 차이는 아래와 같이 직접 계산을 통해 쉽게 구하실 수 있습니다.
var firstDate = new Date(2010, 10, 1);
var secodDate = new Date(2010, 12, 31);
var diffMilSec = firstDate - secodDate;
var diffSec = diffMilSec / 1000;
var diffMin = diffSec / 60;
var diffHour = diffMin / 60;
var diffDay = diffHour / 24;
function getDiffDays(first, second)
{
return (second-first)/(1000*60*60*24)
}
javascript 형변환
eval() 수식 또는 문자열(계산) → 실수
Number() 문자 → 숫자
String() 숫자 → 문자
escape() 한글 → 16진수
unescape() 16진수 → 한글
parseInt(문자열, 진수) 문자열 → 정수(원하는 진수 변환 가능)
parseFloat() 문자열 → 부동소수점, 변환불가일때 NaN 반환
isFinite() 유한수 TRUE, 무한수 FALSE
isNan() 문자 TRUE, 숫자 FALSE
Number() 문자 → 숫자
String() 숫자 → 문자
escape() 한글 → 16진수
unescape() 16진수 → 한글
parseInt(문자열, 진수) 문자열 → 정수(원하는 진수 변환 가능)
parseFloat() 문자열 → 부동소수점, 변환불가일때 NaN 반환
isFinite() 유한수 TRUE, 무한수 FALSE
isNan() 문자 TRUE, 숫자 FALSE
피드 구독하기:
글 (Atom)