[ URL Mapping ]
< form 태그 >
- form태그에서 action 으로 날려보낼 URL 주소를 생성한다.
1. <form action = "http://localhost:8080/login" >
: 사용자 요청 들어오면 저 주소로 날려보낼게
2. <form action = "login" >
: " http://localhost:8080/ " 이후 주소(파일명)만 적기
( " / " 쓰면 안된다.
" / " 쓸거면 다쓰고 안쓸거면 깔끔하게 주소만 적어라 )
< 서블릿 URL 맵핑 >
- form태그에서 action으로 날린 주소를 받아내야한다.
@WebServlet("/login")
- 서블릿 에서 URL 표현은 " / " 로 시작
: "http://localhost:8080 " 이후 주소명
@WebServlet(" / ") : http://localhost:8080/
(- 컨텍스트 포함일 때
@WebServlet(" / ") :현재컨텍스트 의미
"http://localhost:8080/컨텍스트명" 이후 주소명을 적어준다. )
< 서블릿 주소 XML 로 맵핑 >
- @어노테이션으로 주는 방법이 쉽긴지만 얘가 나오기 전에는 xml 을 이용해 맵핑해줬다.
- WebApp => 저장폴더
- WEB-INF/lib => 추가라이브러리 저장위치 mysql jdbc 등
- WEB-INF => web.xml
web.xml => 웹어플리케이션 설정 담당
[ web.xml ]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
<display-name>WAS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name> t </servlet-name>
<servlet-class>Spring.WAS.Servlet.third.ThirdServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> t </servlet-name>
<url-pattern> /third </url-pattern>
</servlet-mapping>
</web-app>
display-name : 컨텍스트(프로젝트) 이름
project이름 = context이름 = webapplication이름(webapp)
<servlet 에서>
servlet-name 임의로 주고
servlet-class : 패키지명포함한 서블릿클래스명
<servlet-mapping> 에서
servalet-name 가져와서
ulr-pattern 을 맵핑한다
'Back to the Servlet' 카테고리의 다른 글
Tomcat 연동 / Tomcat UTF-8 설정 ( intellij ) (0) | 2022.08.06 |
---|---|
Servlet 방식 <= Spring MVC 방식 비교 (0) | 2022.08.05 |
[HTTP 요청방식] get 방식과 post 방식 (0) | 2022.08.05 |
[Servlet] HttpServlet 메소드, Request 와 Response (0) | 2022.08.05 |
WAS 와 Servlet, lifecycle (0) | 2022.08.05 |