개발구조에 맞게끔 src/main/webapp dir 밑에 index.jsp 추가
1 뷰 추가
webapp 우클릭 > new > JSP File을 선택
2 내용추가
index.jsp body 안에 아무내용이나 추가
3 서버와 연결
web.xml 설정 변경 - 프로젝트 시작시 index.jsp를 기본으로 호출하게 바꿈
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4 실행
서버를 실행하고 주소창에 http://localhost:8080/first/ 입력해서 확인
서블릿 설정 - 액션 호출을 .do로 변경
*.do
: .do 요청만 허용
(서블릿에 요청시 .do를 통해서만 전달되고 다른 방식 예) .html 은 차단)
*-servlet.xml : servlet-context.xml명을 바꾸고 인터셉터 추가하려고 수정
root-context.xml : 루트 스프링 컨테이너 설정
(설정은 모든 서블릿과 필터에서 사용되는 루트 스프링 컨테이너 설정인데
추후 다른 곳에서 설정하기 위해서 설정을 바꿈.)
web.xml
<servlet>
<servlet-name>action</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value> /WEB-INF/config/*-servlet.xml </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
root-context.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</context-param>
/WEB-INF/spring/appServlet 디렉토리에 있는 servlet-context.xml을 복사해서, /WEB-INF/config 폴더에 붙여넣고, 이름을 action-servlet.xml로 변경한다.
서블릿 : 사용자 요청을 처리하고 응답함.
서블릿 클래스의 구현 규칙을 지킨 자바 웹 프로그래밍 기술. CGI(Common Gateway Interface)
1 사용자(클라이언트)가 URL을 입력하면 HTTP Request가 Servlet Container로 전송합니다.
2 요청을 전송받은 Servlet Container는 HttpServletRequest, HttpServletResponse 객체를 생성합니다.
3 web.xml을 기반으로 사용자가 요청한 URL이 어느 서블릿에 대한 요청인지 찾습니다.
4 해당 서블릿에서 service메소드를 호출한 후 클리아언트의 GET, POST여부에 따라 doGet() 또는 doPost()를 호출합니다.
5 doGet() or doPost() 메소드는 동적 페이지를 생성한 후 HttpServletResponse객체에 응답을 보냅니다.
6 응답이 끝나면 HttpServletRequest, HttpServletResponse 두 객체를 소멸시킵니다.\
https://addio3305.tistory.com/39
https://mangkyu.tistory.com/14