-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d689256
commit e14098d
Showing
52 changed files
with
2,007 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.87 KB
frontproject/build/classes/frontproject/controller/FrontController.class
Binary file not shown.
Binary file added
BIN
+4.68 KB
frontproject/build/classes/frontproject/controller/SampleTBController.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>frontproject</groupId> | ||
<artifactId>frontproject</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/jstl/jstl --> | ||
<dependency> | ||
<groupId>jstl</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<release>17</release> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
56 changes: 56 additions & 0 deletions
56
frontproject/src/main/java/frontproject/controller/FrontController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package frontproject.controller; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import frontproject.dao.SampleTBDAO; | ||
import frontproject.vo.SampleTBVO; | ||
|
||
/* | ||
frontcontroller는 모든 가상경로를 제일 먼저 받아 역할에 맞는 컨트롤러로 요청을 분기하는 처리를 한다. | ||
*/ | ||
|
||
public class FrontController extends HttpServlet { | ||
|
||
public FrontController() { | ||
super(); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
String requestURL = request.getRequestURI(); // 전체 url(도메인제외) | ||
String contextPath = request.getContextPath(); // 프로젝트 path | ||
|
||
String command = requestURL.substring(contextPath.length() + 1); // 프로젝트 path를 제외한 uri /까지 잘라내 | ||
String[] uris = command.split("/"); | ||
if (uris[0].equals("sampleTB")) { | ||
|
||
SampleTBController sampleTBController = new SampleTBController(); | ||
|
||
sampleTBController.getAction(request, response, uris); | ||
|
||
} | ||
} | ||
|
||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
String requestURL = request.getRequestURI(); // 전체 url(도메인제외) | ||
String contextPath = request.getContextPath(); // 프로젝트 path | ||
|
||
String command = requestURL.substring(contextPath.length() + 1); // 프로젝트 path를 제외한 uri /까지 잘라내 | ||
String[] uris = command.split("/"); | ||
if (uris[0].equals("sampleTB")) { | ||
|
||
SampleTBController sampleTBController = new SampleTBController(); | ||
|
||
sampleTBController.postAction(request, response, uris); | ||
|
||
} | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
frontproject/src/main/java/frontproject/controller/SampleTBController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package frontproject.controller; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.swing.text.View; | ||
|
||
import frontproject.dao.SampleTBDAO; | ||
import frontproject.vo.SampleTBVO; | ||
|
||
public class SampleTBController { | ||
|
||
public void getAction(HttpServletRequest request, HttpServletResponse response, String[] uris) throws ServletException, IOException { | ||
//frontcontroller에서 sampleTB관련 모든 요청을 받아서 각 목적에 맞는 메서드를 분기하는 영역 | ||
|
||
if(uris[1].equals("list.do")) { | ||
list(request,response); | ||
}else if(uris[1].equals("view.do")){ | ||
view(request,response); | ||
}else if(uris[1].equals("modify.do")){ | ||
modify(request,response); | ||
}else if(uris[1].equals("insert.do")){ | ||
insert(request,response); | ||
} | ||
} | ||
public void postAction(HttpServletRequest request, HttpServletResponse response, String[] uris) throws ServletException, IOException { | ||
//post 요청에 대한 처리 | ||
if(uris[1].equals("modify.do")) { | ||
modifyOk(request,response); | ||
}else if(uris[1].equals("insert.do")) { | ||
insertOk(request,response); | ||
} | ||
} | ||
|
||
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
SampleTBDAO sampleTBDao = new SampleTBDAO(); //ctrl shift o | ||
List<SampleTBVO> slist = sampleTBDao.selectList(); | ||
|
||
request.setAttribute("slist", slist); | ||
|
||
RequestDispatcher rd = request.getRequestDispatcher("/sampleTB/list.jsp"); | ||
rd.forward(request, response); | ||
} | ||
|
||
private void view(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
String snoParam = request.getParameter("sno"); | ||
int sno = 0; | ||
if(snoParam != null && !snoParam.equals("")) { | ||
sno = Integer.parseInt(snoParam); | ||
}else { | ||
response.sendRedirect("list.do"); | ||
} | ||
|
||
SampleTBDAO sampleTBDao = new SampleTBDAO(); | ||
|
||
SampleTBVO svo = sampleTBDao.selectOne(sno); | ||
|
||
request.setAttribute("svo", svo); | ||
|
||
RequestDispatcher rd = request.getRequestDispatcher("/sampleTB/view.jsp"); | ||
rd.forward(request, response); | ||
} | ||
|
||
private void modify(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
String snoParam = request.getParameter("sno"); | ||
int sno =0; | ||
if(snoParam != null && !snoParam.equals("")) { | ||
sno = Integer.parseInt(snoParam); | ||
}else { | ||
response.sendRedirect("list.do"); | ||
} | ||
|
||
SampleTBDAO sampleTBDao = new SampleTBDAO(); | ||
|
||
SampleTBVO svo = sampleTBDao.selectOne(sno); | ||
|
||
request.setAttribute("svo",svo); | ||
|
||
RequestDispatcher rd = request.getRequestDispatcher("/sampleTB/modify.jsp"); | ||
rd.forward(request, response); | ||
} | ||
|
||
private void modifyOk(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
request.setCharacterEncoding("utf-8"); | ||
String snoParam = request.getParameter("sno"); | ||
int sno =0; | ||
if(snoParam != null && !snoParam.equals("")) { | ||
sno = Integer.parseInt(snoParam); | ||
} | ||
|
||
String title = request.getParameter("title"); | ||
String writer = request.getParameter("writer"); | ||
String body = request.getParameter("body"); | ||
|
||
SampleTBVO svo = new SampleTBVO(); | ||
svo.setSno(sno); | ||
svo.setTitle(title); | ||
svo.setWriter(writer); | ||
svo.setBody(body); | ||
|
||
SampleTBDAO sampleTBDao = new SampleTBDAO(); | ||
int result = sampleTBDao.update(svo); | ||
|
||
if(result>0) { | ||
//수정성공 | ||
response.sendRedirect("view.do?sno="+sno); | ||
}else { | ||
//수정실패 | ||
response.sendRedirect("modify.do?sno="+sno+"&msg=fail"); | ||
} | ||
} | ||
|
||
private void insert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
RequestDispatcher rd = request.getRequestDispatcher("/sampleTB/insert.jsp"); | ||
rd.forward(request, response); | ||
} | ||
|
||
private void insertOk(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
request.setCharacterEncoding("utf-8"); | ||
SampleTBVO svo = new SampleTBVO(); | ||
svo.setTitle(request.getParameter("title")); | ||
svo.setWriter(request.getParameter("writer")); | ||
svo.setBody(request.getParameter("body")); | ||
|
||
SampleTBDAO sampleTBDao = new SampleTBDAO(); | ||
int result = sampleTBDao.insert(svo); | ||
|
||
response.sendRedirect("list.do"); | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.