spring servlet방식



Java EE Tools 에서 Generate Deployment 클릭
web.xml

html변수를 이용하여 일일이 html태그를 입력해줘야한다.
심지어 out.println까지 작성..
PrintWriter out = response.getWriter();
out.println(html);
out.flush();

web.xml
jsp가 나오기 이전에 웹구현방식.

유지보수가 굉장히 어렵고 불편하다.
서블렛을 이용해서 jsp와 연계하기


commandAction은 인터페이스로 만들어준다.

=>스프링의 컨테이너 방식을 자바코드로 작성한 결과.

httpservlet을 상속받아준다.
public void init() throws ServletException{
String configFile = getInitParameter("configFile");
Properties pro = new Properties();
FileInputStream fis = null;
try {
String configFilePath = getServletContext().getRealPath(configFile);
fis = new FileInputStream(configFilePath);
pro.load(fis);
Set<String> keys = pro.stringPropertyNames();
for(String key: keys) {
String className = pro.getProperty(key);
Class<?> actionClass = Class.forName(className);
CommandAction actionInstance = (CommandAction) actionClass.newInstance();
map.put(key, actionInstance);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(fis != null) try { fis.close(); }catch (Exception e) {}
}
}
init() 준비단계