작은 콩 개발자/등등

Servlet, web.xml

귤치치 2023. 6. 23. 13:19

 2020. 12. 24. 18:40 

* Servlet(Server Applet)

- JAVA언어로 이루어진 웹프로그래밍 문서

(Servlet 3.0)

* Servlet특징

  • 동적 웹애플리케이션 컴포넌트.
  • .java 확장자.
  • 클라이언트의 요청에 동적으로 작동하고, 응답은 html을 이용.
  • java thread이용하여 동작.
  • MVC패턴에서 Controller로 이용됨.

* web.xml에 서블릿 맵핑

너무 길고, 보안에 노출되어 있는 경로를 간단하게 맵핑하는 것이다.

- 서블릿을 상속받은 클래스는 다 서블릿이다. http 프로그램을 잘 사용하도록 캡슐화시킨 라이브러리

기존 경로 : http://localhost:8181/helloworld/servlet/com.javalec.ex.HelloWorld
 
URL맵핑 경로 : http://localhost:8181/helloworld/HWorld

web.xml안을 이렇게 수정해 준다.

<servlet>//hello는 변수명이고

<servlet-name>hello</servlet-name>

<servlet-class>edu.bit.ex.HelloWorld</servlet-class>//이 클래스를 띄어준다.

</servlet>

<servlet-mapping>

<servlet-name>hello</servlet-name>

<url-pattern>/hw</url-pattern>

</servlet-mapping>

그러면 /hw로 접근이 가능해진다.