jaekk 2018. 7. 19. 17:48
ex) localhost/page/list.do?type=aa


URL: localhost/page/list.do?type=aa
URI: /page/list.do

contextPath: /page 


서블릿에서의 핵심 코드


1
2
3
4
5
String command = request.getRequestURI();
 
if(command.indexOf(request.getContextPath()) == 0) {
    command = command.substring(request.getContextPath().length());
}
cs


경로 구하기


1. getRequestURI() 메서드를 이용하여 URI를 구한다.

2. 구한 URI에서 getContextPath() 메서드로 설정 경로의 index번호부터 나머지의 문자를 자른다.