request.getRequestURI() , request.getContextPath() 예제
package servletExam;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/uriExample/*")
public class URIExample extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
proceedRequest(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
proceedRequest(req,resp);
}
private void proceedRequest(HttpServletRequest request, HttpServletResponse response) {
String command = request.getRequestURI(); // /myapplication/uriExample/*
String contextPath = request.getContextPath(); // /myapplication
System.out.println("contextPath = " + contextPath);
System.out.println("command = " + command);
if(command.indexOf(request.getContextPath())==0){
command = command.substring(request.getContextPath().length());
}
System.out.println("command.substring = " + command);
}
}
http://localhost:8080/myapplication/uriExample/boardWrite1234 요청한다면
request.getRequestURI() : /myapplication/uriExample/boardWrite1234
request.getContextPath : /myapplication
command = command.substring(request.getContextPath().length()) : /uriExample/boardWrite1234
jsp filter 한글 필터, 캐릭터 인코딩 필터 (0) | 2020.07.06 |
---|---|
Filter interface, filter setting, 필터 설정, 필터 인터페이스 (0) | 2020.07.06 |
서블릿 리스너 : ServletContextListener 인터페이스 @WebListener (0) | 2020.07.06 |
서블릿 초기화 파라미터 <context-param> (0) | 2020.07.06 |
서블릿 초기화 파라미터 web.xml <init-param> 애노테이션 @WebServlet @WebInitParam (0) | 2020.07.06 |
댓글 영역