๐ป
JSP ํ๋ก๊ทธ๋๋ฐ - ๋ก๊ทธ๋ฉ์์ง/ ํ๋ฌ๊ทธ์ธ ๋ค์ด ๋ณธ๋ฌธ
Command.java
package com.java.mvc05;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Command {
//์์ฒญ์ ๋ํด์ FrontController(์๋ธ๋ฆฟ)์์ ์ง์ ์ฒ๋ฆฌํ์ง ์๊ณ ํด๋น ํด๋์ค๊ฐ ์ฒ๋ฆฌํ๋๋กํ๋ค.
public String actionDo(HttpServletRequest request,
HttpServletResponse response) throws Exception;
}
FrontCnt.java
package com.java.mvc05;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FrontCnt extends HttpServlet {
private static final long serialVersionUID = 1L;
private HashMap<String, Object> commandMap = new HashMap<String, Object>();
public static final Logger logger = Logger.getLogger(FrontCnt.class.getName());
public static String logMsg = "logMsg----------------";
public FrontCnt() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void init(ServletConfig config) throws ServletException {
String configFile = config.getInitParameter("configFile");
System.out.println(configFile);
FileInputStream fis = null;
BufferedInputStream bis = null;
Properties pro = new Properties();
try {
fis = new FileInputStream(configFile);
bis = new BufferedInputStream(fis, 1024);
pro.load(bis);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (bis != null)
bis.close();
if (fis != null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Iterator<Object> keyIter = pro.keySet().iterator();
while (keyIter.hasNext()) {
String key = (String) keyIter.next();
String value = pro.getProperty(key);
logger.info(logMsg + key + "\t" + value);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String cmd = request.getServletPath();
System.out.println(cmd);
// String view = null;
// try {
// Command com = (Command) commandMap.get(cmd);
// view = com.actionDo(request, response);
// }catch(Throwable e) {
// e.printStackTrace();
// }
//
// if(view!=null) {
// RequestDispatcher rd = request.getRequestDispatcher(view);
// rd.forward(request, response);
// }
//
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
ListAction.java
package com.java.mvc05;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ListAction implements Command {
@Override
public String actionDo(HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
request.setAttribute("message", "๋ฆฌ์คํธ");
return "/mvc/list.jsp";
}
}
WriteAction.java
package com.java.mvc05;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WriteAction implements Command {
@Override
public String actionDo(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setAttribute("message", "์ฐ๊ธฐ");
return "/mvc/write.jsp";
}
}
index.jsp
<%@ 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="http://localhost:8181/mvcExample/write.kitri">Controller - ๊ธ์ฐ๊ธฐ</a>
<a href="http://localhost:8181/mvcExample/list.kitri">Controller - ๊ธ๋ชฉ๋ก</a>
<br /><br />
<a href="http://localhost:8181/mvcExample/write.do">SampleController - ๊ธ์ฐ๊ธฐ</a>
<a href="http://localhost:8181/mvcExample/list.do">SampleController - ๊ธ๋ชฉ๋ก</a>
<br /><br />
<a href="http://localhost:8181/mvcExample/write.action">CommandController - ๊ธ์ฐ๊ธฐ</a>
<a href="http://localhost:8181/mvcExample/list.action">CommandController - ๊ธ๋ชฉ๋ก</a>
<br /><br />
<a href="http://localhost:8181/mvcExample/write.happy">FrontController - ๊ธ์ฐ๊ธฐ</a>
<a href="http://localhost:8181/mvcExample/list.happy">FrontController - ๊ธ๋ชฉ๋ก</a>
</body>
</html>
commandURI.properties
/write.happy=com.java.mvc05.WriteAction
/list.happy=com.java.mvc05.ListAction
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>mvcExample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Directory</servlet-name>
<servlet-class>com.java.mvc01.Directory</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Directory</servlet-name>
<url-pattern>*.nhn</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>com.java.mvc02.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>*.kitri</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SampleCnt</servlet-name>
<servlet-class>com.java.mvc03.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>CommandController</servlet-name>
<servlet-class>com.java.mvc04.CommandCnt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CommandController</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FrontCnt</servlet-name>
<servlet-class>com.java.mvc05.FrontCnt</servlet-class>
<init-param>
<param-name>configFile</param-name>
<param-value>C:\sohyunkim\mvc\workspace\mvcExample\WebContent\WEB-INF\commandURI.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>FrontCnt</servlet-name>
<url-pattern>*.happy</url-pattern>
</servlet-mapping>
</web-app>
๋ก๊ทธ ๋ฌธ์ ์์ ๋ณ๊ฒฝ , ๋ฐฐ๊ฒฝ ์ค์ ํ๋ก๊ทธ๋จ ๋ค์ด๋ก๋
Help >> Install New Software ...
2. console ์ฐฝ์ INFO ๋ก๊ทธ๋ฅผ ๋ธ๋ญ์ผ๋ก ์ ํํ ํ ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค
Add Expression >> Log Output >> Styles & Links >> ์ํ๋ ์คํ์ผ ์ ํ or New๋ก ์์ฑ
์ ์ ์ฉ์ด ๋จ์ ํ์ธํ ์ ์๋ค.
๋ฐ์ํ
'KITRI > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments