스트럿츠에서 web.xml , strus-config.xml 등의 설정파일을 수정하고나면 반드시 톰캣을 재가동해줘야 했다. 너무 번거롭고 짜증나지 아니한가.....
스트럿츠 프레임워크 워크북에는 ActionServlet을 확장한 클래스를 새로 만들면 된다고 나왔다.. 헌데 책이 좀 오래된지라... 옛날버젼..
1.2버전이후에는 스트럿츠 패키지가 좀 바뀌었나 부다... 책대로 했는데 안되네....
자... 일단
1.MyAppServlet.java를 만들자..(ActionServlet)을 상속받은 것이다.
패키지도 하나 새로 만들자.. struts.action 으로 했다.
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.ModuleUtils;
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String uri = request.getRequestURI();
init();
//RequestUtils.selectModule(request, getServletContext());
//하지만 스트럿츠버전이 업데이트됨에 따라 RequestUtils패키지를 쓰지 않는다.
ModuleUtils.getInstance().selectModule(request, getServletContext()); //1.2버전이후...
ModuleConfig config = getModuleConfig(request);
getRequestProcessor(config).init(this, config);
request.getRequestDispatcher("/reload.jsp");
dispatcher.forward(request, response);
} else {
super.process(request, response);
}
}
}
2.ReloadStrutsConfigAction.java 파일 생성 (Action클래스 상속)
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public ActionForward excute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{
return null;
}
3.web.xml 설정 수정
<servlet-class>struts.action.MyAppServlet</servlet-class>
4.struts-config.xml 설정 추가
path="/reload"
type="struts.action.ReloadStrutsConfigAction">
</action>
다 되었다. 이제 주소창에 http://서버주소/컨텍스트패스/reload.do로 해보자..
그럼 404페이지 reload.jsp가 뜨겠지... 요건 상관없지만(jsp페이지를 만들어줘도 상관없다.)
정상적으로 리로딩이 된다. 테스트해보면 된다. struts-config.xml 파일에서
<action
path="/login1/Form"
forward="/login1/logInForm.jsp"/>
요런 설정을 패스를 바꾸고
<action
path="/login1/logInForm"
forward="/login1/logInForm.jsp"/>
요렇게 바꾸고 저장 후 reload.do를 하면 바뀐 설정이 바로 적용된다.
이제 편하게 개발해보장~