<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>do1.jsp</h3>
${result }
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>do2.jsp</h3>
${result }
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>do3.jsp</h3>
${result }
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="do1.do">링크1</a><br>
<a href="do2.do">링크2</a><br>
<a href="do3.do">링크3</a><br>
</body>
</html>
코드를 입력하세요
package com.koreait.web.servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Do2 {
public String execute(HttpServletRequest req, HttpServletResponse resp) {
req.setAttribute("result", "do2으로 요청보내기");
return "do2.jsp";
}
}
package com.koreait.web.servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Do3 {
public String execute(HttpServletRequest req, HttpServletResponse resp) {
req.setAttribute("result", "do3으로 요청보내기");
return "do3.jsp";
}
}
package com.koreait.web.servlet;
import java.io.IOException;
import java.net.http.HttpRequest;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("*.do")
public class DoFrontController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doProcess(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doProcess(req, resp);
}
protected void doProcess(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("URI : " + req.getRequestURI());
String requestURI = req.getRequestURI();
String responseURI = null;
if(requestURI.equals("/do1.do")) {
responseURI = new Do1().execute(req, resp);
}else if(requestURI.equals("/do2.do")) {
responseURI = new Do2().execute(req, resp);
}else if(requestURI.equals("/do3.do")) {
responseURI = new Do3().execute(req, resp);
}
req.getRequestDispatcher(responseURI).forward(req, resp);
}
}
출처
https://media.giphy.com/media/dwmNhd5H7YAz6/giphy.gif
https://media.giphy.com/media/3o6Mb9EC7mNqXl9x7y/giphy.gif