생활
MVC 패턴 서블릿 컨트롤러 관련 질문입니다
요것땜시 며칠째 스터디 스탑 상태에 있습니다. 지금은 .. 머.. 코스피 상태라고 할까요..흐흐..
web.xml과 CommandPro.properties라는 같은 폴더에 있는 문서(?)와.. 서블릿 컨트롤러의 관계가 사람을 패닉 상태로 만들어 놓으네요..
질문이 좀 길 수 있습니다. 최대한 정리해서 올리겠습니다.
우선 web.xml 중요부분 코딩입니다.
<servlet>
<servlet-name>ControllerAction</servlet-name>
<servlet-class>ch19.controller.ControllerAction</servlet-class>
<init-param>
<param-name>propertyConfig</param-name>
<param-value>D:/Study/JAVA/Report/Jsp2/Jsp2/WebContent/WEB-INF/CommandPro.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ControllerAction</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
CommandPro.properties 의 문서 코딩입니다.
/ch19/list.do=ch19.action.ListAction
/ch19/writeForm.do=ch19.action.WriteFormAction
/ch19/writePro.do=ch19.action.WriteProAction
/ch19/content.do=ch19.action.ContentAction
/ch19/updateForm.do=ch19.action.UpdateFormAction
/ch19/updatePro.do=ch19.action.UpdateProAction
/ch19/deleteForm.do=ch19.action.DeleteFormAction
/ch19/deletePro.do=ch19.action.DeleteProAction
위의 두 파일은 같은 폴더에 있구요..
마지막으로 서블릿 컨트롤러 코딩 부분입니다.
package ch19.controller;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.jasper.tagplugins.jstl.core.Out;
import ch19.action.CommandAction;
public class ControllerAction extends HttpServlet{
private Map commandMap = new HashMap();//명령어와 명령어 처리 클래스를 쌍으로 저장
//명령어와 처리클래스가 매핑되어 있는 properties 파일을 읽어서 Map객체인 commandMap에 저장
//명령어와 처리클래스가 매핑되어 있는 properties 파일은 Command.properties파일
public void init(ServletConfig config) throws ServletException {
String props = config.getInitParameter("propertyConfig");//web.xml에서 propertyConfig에 해당하는 init-param 의 값을 읽어옴
Properties pr = new Properties();//명령어와 처리클래스의 매핑정보를 저장할 Properties객체 생성
FileInputStream f = null;
try {
f = new FileInputStream(props); //Command.properties파일의 내용을 읽어옴
pr.load(f);//Command.properties파일의 정보를 Properties객체에 저장
} catch (IOException e) {
throw new ServletException(e);
} finally {
if (f != null) try { f.close(); } catch(IOException ex) {}
}
Iterator keyIter = pr.keySet().iterator();//Iterator객체는 Enumeration객체를 확장시킨 개념의 객체
while( keyIter.hasNext() ) {//객체를 하나씩 꺼내서 그 객체명으로 Properties객체에 저장된 객체에 접근
String command = (String)keyIter.next();
String className = pr.getProperty(command);
try {
Class commandClass = Class.forName(className);//해당 문자열을 클래스로 만든다.
Object commandInstance = commandClass.newInstance();//해당클래스의 객체를 생성
commandMap.put(command, commandInstance);// Map객체인 commandMap에 객체 저장
} catch (ClassNotFoundException e) {
throw new ServletException(e);
} catch (InstantiationException e) {
throw new ServletException(e);
} catch (IllegalAccessException e) {
throw new ServletException(e);
}
}
}
public void doGet(//get방식의 서비스 메소드
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
requestPro(request, response);
}
protected void doPost(//post방식의 서비스 메소드
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
requestPro(request, response);
}
//시용자의 요청을 분석해서 해당 작업을 처리
private void requestPro(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String view = null;
CommandAction com=null;
try {
String command = request.getRequestURI();
if (command.indexOf(request.getContextPath()) == 0) {
command = command.substring(request.getContextPath().length());
}
com = (CommandAction)commandMap.get(command);
view = com.requestPro(request, response);
} catch(Throwable e) {
throw new ServletException(e);
}
RequestDispatcher dispatcher =request.getRequestDispatcher(view);
dispatcher.forward(request, response);
}
}
요건 다 올렸습니다.
이걸 list.jsp란 파일을 만들어서 write.jsp로 보내려고 합니다.
<a href="/Jsp2/ch19/writeForm.do">글쓰기</a>
요런 링크를 걸어서 말이죠..
그럼..
HTTP Status 500 -type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: ch19.action.UpdateFormAction ch19.controller.ControllerAction.init(ControllerAction.java:39) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) java.lang.Thread.run(Unknown Source)root cause
java.lang.ClassNotFoundException: ch19.action.UpdateFormAction org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1363) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209) java.lang.ClassLoader.loadClassInternal(Unknown Source) java.lang.Class.forName0(Native Method) java.lang.Class.forName(Unknown Source) ch19.controller.ControllerAction.init(ControllerAction.java:35) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) java.lang.Thread.run(Unknown Source)note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
요런.. 메세지가 뜨네요..
해서.. 서블릿 부분을..대량 주석처리했죠..
요러케요.
package ch19.controller;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.jasper.tagplugins.jstl.core.Out;
import ch19.action.CommandAction;
public class ControllerAction extends HttpServlet{
public void init(ServletConfig config) throws ServletException {
}
public void doGet(//get방식의 서비스 메소드
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
requestPro(request, response);
}
protected void doPost(//post방식의 서비스 메소드
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
requestPro(request, response);
}
//시용자의 요청을 분석해서 해당 작업을 처리
private void requestPro(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher =request.getRequestDispatcher("/ch19/writeForm.jsp");
dispatcher.forward(request, response);
}
}
ㅋㅋㅋ 기냥 빵강색 부분만 리턴시키겠다는건데.. 그럼 잘 넘어갑니다...
분명 서블릿컨트롤러 부분에 init메소드와 requestPro메소드의 문제 같은데요..
어디서 찾아야 할지 모르겠네요..
아직 답변이 없어요.