메뉴 건너뛰기

조회 수 4705 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

get 으로 전송된 파라메타 쿼리문자열을 컨트롤하는 클래스 입니다.
쿼리문자열 : request.getQueryString();


Java Source : Strings.java

package xf.common;
 
/*
'// Strings
'// programmed by 최석균
'// http://www.cyworld.com/syaku
'// http://syaku.tistory.com
*/
 
import java.util.regex.*;
import java.text.*;

public class Strings {
 
  // Method get 파라메터 컨트롤러
  public static String getParameter(String parameter,String update) {
    // 파라메터를 담을 HashMap
    HashMap params = new HashMap();
    // 패턴
    String patten = "^(.*)=(.*)$";
    Pattern para_patten = Pattern.compile(patten,Pattern.MULTILINE);
   
    if (parameter != null && parameter != "") {
     
      String para = parameter.replaceAll("^\\?","");
      String para_tokens[] = para.split("&");
      int para_cnt = para_tokens.length;
      for (int i = 0; i < para_cnt; i++ ) {       
        Matcher para_matcher = para_patten.matcher(para_tokens[i]);
        String para_name = para_matcher.replaceAll("$1");
        String para_value = para_matcher.replaceAll("$2");
        params.put(para_name,para_value);
      }
    }
   
    if (update != null && !update.equals("")) {
      String new_para = update.replaceAll("^\\?","");
      String new_para_tokens[] = new_para.split("&");
      int new_para_cnt = new_para_tokens.length;
      for (int x = 0; x < new_para_cnt; x++ ) {       
        Matcher new_para_matcher = para_patten.matcher(new_para_tokens[x]);
        String new_para_name = new_para_matcher.replaceAll("$1");
        String new_para_value = new_para_matcher.replaceAll("$2");
        params.put(new_para_name,new_para_value);
      }
    }
   
    // 완성된 HashMap key 로드
    String params_ext = "";
    Iterator iter = params.keySet().iterator();
    while(iter.hasNext()){
      String addkey = (String)iter.next();
      String addvalue = (String)params.get(addkey);
      // 값이 있는 파라메터만 유효
      if (addvalue != null && !addvalue.equals("")) params_ext += addkey + "=" + params.get(addkey) + "&";     
    }
    params_ext = params_ext.replaceAll("&$","");
    return params_ext;
  }
}


Example Source


<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>

<%@ page import="xf.common.*" %>

<%
// String parameter = request.getQueryString();
String parameter = "chn=syaku&mode=blog&search=&page=1";

// 현 파라메터 정보
out.println(parameter + "<br />");
// 결과 : chn=syaku&mode=blog&search=&page=1

// chn=secon 변경하기
out.println(Strings.getParameter(parameter,"chn=secon") + "<br />");
// 결과 : chn=secon&mode=blog&page=1 : &search= 값이 없기 때문에 자동 제거 됨.

// page 파라메터 삭제하기
out.println(Strings.getParameter(parameter,"page=") + "<br />");
// 결과 : chn=secon&mode=blog

// page=2 를 추가하고, mode=home 변경하며, chn 파라메터는 삭제하기.
out.println(Strings.getParameter(parameter,"chn=&mode=home&page=2") + "<br />");
// 결과 : mode=home&page=2
%>




List of Articles
번호 제목 날짜 조회 수
111 public static void main(String [] args) 2016.09.13 3143
110 Reflection을 활용한 메서드, 필드 값 불러오기. 2021.03.31 124
109 request header 로부터 접속 정보 확인 file 2023.02.15 75
108 Select statements cannot be executed as an update. 에러 해결방법 file 2016.08.29 3853
107 set get 파라미터 2016.08.18 3658
106 Singleton Pattern 과 DeadLock file 2023.02.15 74
105 Spring Boot 프로젝트 생성 file 2016.09.02 4160
104 static 2016.09.13 3354
103 static멤버와 관련된 예제 2016.09.21 3768
102 System.out.println(); 이클립스에서 자동화기능 사용 file 2016.09.19 5158
101 TCP 소켓 프로그래밍 01 - Server/Client 일대일 연결 file 2021.03.31 119
100 war로 묶지 않아도 컴파일된 소스 위치 확인하기 file 2016.08.29 4116
99 XML to JSON , JSON to Map 2020.06.29 262
98 [객체 지향 언어의 이해] 업캐스팅과 다운캐스팅 file 2021.03.31 157
97 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서04.jdbc 드라이버 설치 file 2016.08.18 4209
96 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서07.commons-collection 설치 file 2016.08.18 3845
95 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ] 이클립스 프로젝트 생성 순서08.commons-logging 설치 file 2016.08.18 4458
94 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]11. 이클립스 프로젝트 생성 file 2016.08.18 3972
93 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동 ]9. 이클립스 압타나 플러그인 설치 file 2016.08.18 4012
92 [자바(스프링&mybatis&jsp) 프로젝트 & 아파치 &톰켓 연동]3. 이클립스 설치 file 2016.08.18 3756
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved