기본 콘텐츠로 건너뛰기

글

라벨이 java인 게시물 표시

2022 08 26 회사 워크샵

https, http 세션공유 JSP

HTTPS<->HTTP, 세션 공유 Tomcat 서버에서 로그인 페이지처럼 특정 페이지는 HTTPS를 이용하고, 나머지 페이지는 HTTP를 사용하려고 한다. 이때 HTTPS->HTTP로 이동하면서 세션은 공유되지 않는 문제가 있다. 다음은 이 문제를 해결하는 방법 중 하나이다. RequestWrapper 클래스를 하나 만듭니다. 이 클래스는 HTTPS 요청일 경우 쿠키에 세션 정보를 조작하는 역할을 합니다. ========================================================= public class HttpsRequestWrapper extends HttpServletRequestWrapper{  private HttpServletResponse response = null;  public HttpsRequestWrapper (HttpServletRequest request) {   super(request);  }  public void setResponse (HttpServletResponse response) {   this.response = response;  }  public HttpSession getSession () {   HttpSession session = super.getSession();   processSessionCookie(session);   return session;  }  public HttpSession getSession (boolean create) {   HttpSession session = super.getSession(create);   processSessionCookie(session);   return session;  }  private void pro...

java string.format

★ 내용 - C의 printf()와 같은 기능 - 날짜 이외에도 표시할 수 있다. - %d : 정수 - %s : 문자 - %f : float형 소수 ★ 예제 String str = String.format("H_%d", 2); // String str = H_2; String str2 = String.format("H_%d", 3); // String str2 = H_3; ★ 심화 - %02d : 둘째 자리에 정수를 받아 넣는데 만약 한자리의 정수가 오면 앞에 '0'을 붙이고 정수가 붙음 즉, 1을 넣으면 => 01 12를 넣으면 => 12 [출처] [Java] String.format()|작성자 길상

jad -- class > java 로 변환

그 유명한? JAD!!  이클립스로 설치 가능한데 어디가 막혔는지 설치가 되질 않는다..-_-;; 남이 만든 소스를 보고 싶을 때 아주 유용한 프로그램 되시겠다.(사실 class 파일만 있어서 사용한거에요. 남의거 배낄려고 하는거 아네요)  jad.zip 압축을 풀면 jad.exe 파일이 있다. 디컴파일시킬 프로그램은 같은 폴더안에 넣어준다.(아니면 경로를 써야하므로) cmd로 해당 jad 폴더로 들어갑니다. 명령어는 jad hlep를 보고 싶으시면 커맨드 창에 jad를 치거나 폴더안의 readme를 읽어주시길. 이제 디컴파일의 명령어를 해보자. >jad -o -s jad <클래스이름>  -o 는 무조건 덮어쓴다. -s 는 완료하면 jad를 끝낸다 이다.  위와 같은 문구가 보인다면 폴더로 가보자. 기대하던 java 파일이 당신을 기다리고 있을것이다.

인코딩 확인

String value="테스트";   String charSet[] = {"euc-kr", "ksc5601", "iso-8859-1", "8859_1", "ascii", "UTF-8"};  for(int k = 0; k < charSet.length; k++) {                for(int j = 0; j < charSet.length; j++) {                System.out.println(charSet[k] + " to " + charSet[j] + " = " + new String(value.getBytes(charSet[k]),charSet[j]));                 }         }

Jquery Json list 배열 입력

클라이언트에서 ajax로 요청했을 때 자료를 손쉽게 파싱하기 위해서 json으로 클라이언트에 던져줄 때가 편할 때가 있습니다. 그래서 손쉽게 json으로 변환하는 라이브러리가 있습니다. http://json-lib.sourceforge.net/ 여기보면 json-lib라는 놈이 있는데 json으로 손쉽게 변환해주는 라이브러리입니다. jakarta commons-lang 2.3 jakarta commons-beanutils 1.7.0 jakarta commons-collections 3.2 jakarta commons-logging 1.1 ezmorph 1.0.4 이것들이 필요하다더군요. 위에 4개는 apache에 가면 있구요. ezmorph는 구글링해서 찾아서 받으세요. 그리고 JSON-LIB인 json-lib-2.2.1-jdk15.jar가 필요합니다. 사용법은 매우 간단합니다. [code] public class JsonTest {  @Test  public void Bean2Json()  {   MyBean myBean1 = new MyBean();   myBean1.setId(1);   myBean1.setName("mudchobo");   MyBean myBean2 = new MyBean();   myBean2.setId(2);   myBean2.setName("shit");   List<MyBean> mybeanList = new ArrayList<MyBean>();   mybeanList.add(myBean1);   mybeanList.add(myBean2);   JSONArray jsonArray = JSONArray.fromObject(mybeanList);   System.out.println("mybeanList - " + jsonArray);...

java String encoding

[Java] String Encoding Dev/java/flex/jsp/js JAEYOUNG CHOI  님의 블로그에서 무단 펌한 글이다. 모든 String 은 기본적으로 file.encoding 을 따라간다. - API - string .getBytes( charset ) 해당  string  의  charset  인코딩 바이트 배열을 얻는다. (다른 인코딩의 Writer 등에 바이트를 써야할 때 사용) new String( bytes ) 해당 bytes 를 file.encoding 인코딩 바이트 배열로 보고 string 을 만들어낸다. new String( bytes ,  charset ) 해당  bytes  를  charset  인코딩 바이트 배열로 보고 string 을 만들어낸다. 솔린IX  님의 블로그에서 무단 펌한 글이다. o(new String(word.getBytes("utf-8"), "euc-kr")); o(new String(word.getBytes("utf-8"), "ksc5601")); o(new String(word.getBytes("utf-8"), "x-windows-949")); o(new String(word.getBytes("utf-8"), "iso-8859-1")); o(new String(word.getBytes("iso-8859-1"), "euc-kr")); o(new String(word.getBytes("iso-8859-1"), "ksc5601")); o(new String(word.getBytes("iso-8859-1"), "x-windows-949")); o(new String(word.getBytes(...

java 간단한 시간 찍기

long startTime = System.currentTimeMillis();   System.out.println("Job 시작 시간 : "+ new Timestamp(startTime)); Calendar calendar = Calendar.getInstance();    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");   System.out.println("현재 시간 : " + dateFormat.format(calendar.getTime())); 출처 : http://blog.naver.com/nanandayo/60057993543

java 에서 쓰이는 형변환

자바 형변환입니다. ... 문뜩 까먹어서 ㅎㅎ 적어놓기! int to String String str =" "+ i; String to int int i = Integer.parseInt(str); int i = Integer.valueOf(str).intValue(); double to String String str = Double.toString(d); long to String String str = Long.toString(l); float to String String str = Float.toString(f); String to double double d = Double.valueOf(str).doubleValue(); String to long long l = Long.valueOf(str).longValue(); long l = Long.parseLong(str); String to float float f = Float.valueOf(str).floatValue(); decimal to binary String binstr = Integer.toBinaryString(i); decimal to hexadecimal String hexstr = Integer.toString(i, 16); String hexstr = Integer.toHexString(i); Integer.toHexString( 0x10000 | i).substring(1).toUpperCase()); hexadecimal(String) to int int i = Integer.valueOf("B8DA3", 16).intValue(); int i = Integer.parseInt("B8DA3", 16); ASCII Code to String String char = ...