본문 바로가기

Develop

(162)
request 내용 확인 HTTP method 확인String method = request.getMethod();cs ContextPathString cp = request.getContextPath();//: /studycs 요청 URLString url = request.getRequestURL().toString();//http://localhost:9090/study/0222/test3_ok.jsp String path = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); //http://localhost:9090/studycs URL에서 스키마, 서버이름, 포트번호를..
공백, 줄바꿈 등 제거 $('#id').val().replace(" ", "") -> 첫번째 공백 1개만 없어짐. $.trim($('#id').val()) -> 글자사이 공백은 안없어짐. $('#id').val().replace(/ /g, ''); -> 모든 공백 없어짐. $('#id').val().replace(/,/g, ''); -> 모든 콤마(,) 없어짐. function trim(value){value = value.replace(/\s+/, "");//왼쪽 공백제거value = value.replace(/\s+$/g, "");//오른쪽 공백제거value = value.replace(/\n/g, "");//행바꿈제거value = value.replace(/\r/g, "");//엔터제거return value;}
숫자 체크 (isNaN, jQuery.isNumeric, 정규식) 자바스크립트에서 숫자 체크는 정규식, isNaN, jQuery 등 여러가지 방법이 있습니다.아래에 코드와 테스트한 결과를 올려놓았으니 본인이 원하는 상황에 맞게 사용하세요.isNaN( value )자바스크립트에서 isNaN 은 숫자가 아닌 값을 찾는 함수입니다.isNaN ( value ) 의 value가 숫자가 아니라면 true, 숫자라면 false라는건데..원하는대로 나올까요?숫자가 true로 반환하려면 반대로 해야겠죠? !isNaN( value )로 테스트 해봅시다.123456789101112131415161718192021!isNaN( "-10" ) // true!isNaN( "+10" ) // true!isNaN( "0" ) // true!isNaN( "0xFF" ) // true!isNaN( "..
자바스크립트에서 REPLACE를 REPLACEALL 처럼 사용하기 자바스크립트에서 replaceAll 은 없다. 정규식을 이용하여 대상 스트링에서 모든 부분을 수정해 줄 수 있다. [replace 이용] ex) str.replace(“#”,””); -> #를 공백으로 변경한다. 하지만 첫번째 # 만 공백으로 변경하고 나머지는 변경이 되지 않는다. [정규식 이용해서 gi 로 감싸기] str.replace(/#/gi, “”); -> #를 감싼 따옴표를 슬래시로 대체하고 뒤에 gi 를 붙이면 replaceAll 과 같은 결과를 볼 수 있다. [정규식의 gi 설명] * g : 발생할 모든 pattern에 대한 전역 검색 * i : 대/소문자 구분 안함 * m: 여러 줄 검색 (참고) var str = "a1b1c1d1e"; str.replace(/1/gi,""); str = ..
특정 node 값 받아오기 String copyright_path = g_content_country_locale_url+"/jcr:content/footer/footer-copyright";Resource resources = resourceResolver.getResource(copyright_path);Node rootNode = resources.adaptTo(Node.class);String footer_copyright = rootNode.getProperty("text").getString();--- Result ----------------------------------------------------------------- PageManagerhttps://docs.adobe.com/docs/en/cq/5-6-1..
CQ/AEM Best Practices CQ/AEM Best PracticesStructure & Components:Make sure what you are building does not already exist: CQ is huge. There are 307 OSGi bundles and approximately 34 foundational components, 2 custom taglibs comprising 13 tags, a dozen or so standard JSP actions, with as many JSP Core tags and many other CQ components specific to add-ons. The chance the core of what you are building already exists in ..
string(문자열) 비교 ==, equals 의 차이 == 는 선언된 변수가 참조하는 메모리 주소를 비교함equals()는 선언된 변수의 값을 비교함 예시) 출력 String testVal : String testVal2 : String testVal3 = new String("test") : 비교 if(testVal == testVal2) : if(testVal == testVal3) : if(testVal.equals(testVal2)) : if(testVal.equals(testVal3)) : 실행해보면 true, false, true, true 순으로 결과 나올것이다. java에서는 선언된 변수의 값이 같으면 같은 메모리를 참조하기 때문에 == 를 사용해서 비교를 하면 true가 나오지만 new String()을 통해서 생성된 변수는 값이 같아도 새..
올바른 equals() 사용법 java, jsp에어 가장 빈번하게 사용되는 문자열 관련 함수는 비교 함수 equals() 일것입니다. equals()는 보통 이런 형태로 많이들 사용할 것입니다. 변수.equals(비교문자열) 이 형태는 변수의 값이 절대적으로 null이 나오지 않을 경우에는 상관이 없습니다. 하지만 requst.getParameter()를 사용해서 변수의 값을 초기화 한다거나 변수의 값이 수시로 바뀔 수 있는 상황에서는 null 이 들어올수 있습니다. 변수.equals(비교문자열) 이 형태에서 변수에 null 이 들어오게 되면 Exception 이 발생하나는건 잘 아실겁니다. 하지만 비교문자열.equals(변수) 형태로 문자열을 비교한다면 변수에 null 이 들어와도 Exception 이 발생하지 않습니다.(false..