HttpServletRequest : 클라이언트가 서버에게 보낸 요청을 추상화한 객체
HttpServletResponse : 서버가 클라이언트에게 응답하기 위한 정보를 추상화한 객체
실습
http://localhost:8080/firstweb/info
package name : examples
class name : InfoServlet
url mapping : /info
Servlet 생성
서블릿 파일을 요청할 때 지정할 서블릿 이름을 info
으로 하기 위해 수정
InfoServlet.java 생성
package examples;
(생략)
@WebServlet("/info")
public class InfoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public InfoServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Info</title></head>");
out.println("<body>");
out.println("<p style='font-size:25px'>");
String uri = request.getRequestURI();
StringBuffer url = request.getRequestURL();
String contextPath = request.getContextPath();
String remoteAddr = request.getRemoteAddr();
out.println("uri : " + uri + "<br>");
out.println("url : " + url + "<br>");
out.println("contextPath : " + contextPath + "<br>");
out.println("remoteAddr : " + remoteAddr + "<br>");
out.println("</p>");
out.println("</body>");
out.println("</html>");
}
}
📍 출력
contextPath : 웹 어플리케이션과 매핑된 Path
WAS 내의 웹 어플리케이션을 찾아가는 이름 ( 직접 지정 가능 )
remoteAddr : 클라이언트의 주소값