[url-pattern]
- 디렉토리 패턴
. 디렉토리 형태로 서버의 해당 컴포넌트를 찾아서 실행하는 패턴
url 맵핑
http://localhost:8080/jsp_Ex_3/abc -----------------> /abc 서블릿
http://localhost:8080/jsp_Ex_3/ddd -----------------> /ddd 서블릿
- 확장자 패턴
. 확장자 형태로 서버의 해당 컴포넌트를 찾아서 실행하는 패턴
http://localhost:8080/jsp_Ex_2/aaa.do------------------> +----------+
|*.do 서블릿|
http://localhost:8080/jsp_Ex_3/bbb.do------------------> +----------+
[FrontController 패턴]
클라이언트 요청1 --------> 요청1 서블릿 -------->
클라이언트 요청2 --------> 요청2 서블릿 --------> DAO
클라이언트 요청3 --------> 요청3 서블릿 -------->
클라이언트 요청4 --------> 요청4 서블릿 -------->
클라이언트 요청1 -------->
클라이언트 요청2 --------> 모든 요청을 직접
클라이언트 요청3 --------> 처리하는 서블릿 --------> DAO
클라이언트 요청4 -------->
[Command 패턴]
interface 구현
클라이언트 요청1 --------> ---> 요청1 클래스
클라이언트 요청2 --------> 모든 요청을 직접 ---> 요청2 클래스
클라이언트 요청3 --------> 처리하지 않는 서블릿 ---> 요청3 클래스 -----> DAO
클라이언트 요청4 --------> ---> 요청4 클래스
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<a href="insert.do">삽입</a>
<hr width=500 />
<a href="http://localhost:8080<%=request.getContextPath()%>/update.do">업데이트</a>
<hr width=500 />
<a href="http://localhost:8080/jsp_Ex_3/select.do">조회</a>
<hr width=500/>
<a href="<%=request.getContextPath()%>/delete.do">삭제</a>
</center>
<br>
getContextPath: <%=request.getContextPath()%>
</body>
</html>
------------------------------------------------------------------
FrontController.java
package jsp_Ex03;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class FrontController
*/
@WebServlet("*.do")
public class FrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FrontController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doGet");
actionDo(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doPost");
actionDo(request, response);
}
protected void actionDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
System.out.println("actionDo");
String uri = request.getRequestURI();
System.out.println("uri :"+uri);
String conPath=request.getContextPath();
System.out.println("conPath :"+ conPath);
String command =uri.substring(conPath.length());
System.out.println("command :"+command);
if(command.equals("/insert.do")){
System.out.println("insert");
System.out.println("-----------------");
}else if(command.equals("/update.do")){
System.out.println("update");
System.out.println("-----------------");
}else if(command.equals("/select.do")){
System.out.println("select");
System.out.println("-----------------");
}else if(command.equals("/delete.do")){
System.out.println("delete");
System.out.println("-----------------");
}
}
}
'기존카테고리 > JSP' 카테고리의 다른 글
리다이렉트 방식과 요청디스패치 방식의 차이 (0) | 2017.06.21 |
---|---|
Command 패턴 (0) | 2017.06.21 |
공지사항 - 파일 쓰기, 읽기 (0) | 2017.06.13 |
JSTL (0) | 2017.06.13 |
EL(Expression Language) 2 (0) | 2017.06.13 |