1. web-xml 에 들어가서
1
2
3
4
5
6
7
8
|
<servlet>
<servlet-name>FrontController</servlet-name>
<servlet-class>jspstudy.controller.FrontController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
|
cs |
2. Controller 에서 Frontcontrooler 똑같이 맞춰주세요 !! !
3. 가상경로 만들어주기 !!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
@WebServlet("/FrontController")
public class FrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri = request.getRequestURI();
System.out.println("uri =" +uri);
String pj = request.getContextPath();
System.out.println("pj =" +pj);
String command = uri.substring(pj.length()); //프로젝트이름을 뺀 나머지 가상경로 추출
System.out.println("command =" +command);
// ex) /member/memberList.do
String[] subpath = command.split("/");
String location = subpath[1]; // member 문자열이 추출
if (location.equals("member")) {
MemberController mc = new MemberController();
mc.doGet(request, response);
}else if (location.equals("board")) {
BoardController bc = new BoardController();
bc.doGet(request, response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
|
cs |
4. 가상경로에 맞는 컨트롤러로 이동 !
5. 가상경로에 맞는 컨트롤러로 이동 !
6. command 값과 같은 주소값을 매핑시켜서 맞으면 로직 실행 !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
@WebServlet("/BoardController")
public class BoardController extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//가상경로로 온 request가 있으면 처리
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String uri = request.getRequestURI();
String pj = request.getContextPath();
String command = uri.substring(pj.length());
int sizeLimit = 1024*1024*15;
String uploadPath="E:\\openApi(B)\\dev\\jspstudy\\src\\main\\webapp\\";
String saveFolder="images";
String saveFullPath = uploadPath+saveFolder;
if (command.equals("/board/boardWrite.do")) {
System.out.println("글쓰기 화면에 들어왔음");
RequestDispatcher rd = request.getRequestDispatcher("/board/boardWrite.jsp");
rd.forward(request, response);
|
cs |
6. 이상으로 다음은 회원가입을 해볼게용
'기존 > 🏀Jsp' 카테고리의 다른 글
[JSP-3편](mysql) 회원가입 구현하기 dao (0) | 2022.07.20 |
---|---|
[JSP-2편](oracle) web.xml mapping 설정 (0) | 2022.07.20 |
[JSP-1편](oracle) db 연결 jar 파일 포함 (0) | 2022.07.20 |
[JSP-1편](mysql) db 연결 jar 파일 포함 (0) | 2022.07.20 |
[JSP] 쿠키로 만든 조회수 중복 방지 구현 (3) | 2022.06.08 |