hi ,
i m making a web application using the MVC model arch. i m getting the error " java.lang.StackOverflowError" till now my app. includes
a servlet "ControllerServelet"
a request handler interface "RequestHandler"
a request handler class "Initialization"
and a jsp page "choice.jsp
this is the code
public class ControllerServlet extends HttpServlet
{
// Hash table of RequestHandler instance , keyed by request URL
private Map handlerHash = new HashMap();
// Initialize mappings: not implemented here
public void init() throws ServletException
{
// This will read mapping definitions and populate handlerHash
handlerHash.put("/resources/choice.jsp",new handlerpkg.Initialization());
}
/**
* Based on the USRL within our application , choose a RequestHandler
* to handle the request and deletgating processing to it.
* Return an HTTP error Code 404 (not found ) id there's no RequestHandler
* mapped to this URL
*/
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
RequestHandler rh = (RequestHandler)handlerHash.get(request.getServletPath());
if(rh==null)
{
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
else
{
//if we get to here, we have a handler for this request
String viewURL= rh.handleRequest(request,response);
if(viewURL==null)
{
//The RequestHandler has finished output: do nothing
}
else
{
// The RequestHandler told us the view to use
// Forward the response to it
request.getRequestDispatcher(viewURL).forward(request,response);
//response.sendRedirect(viewURL);
}
}
}
}
public interface RequestHandler
{
/**
* @return the URL of the view that should render the response
* (probably a jsp) , or null to indicate that the response has been
* generated already and processing is complete.
*/
String handleRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException;
}
public class Initialization implements RequestHandler
{
/**
* @return the URL of the view that should render the responnse
* (probably a jsp), or null to indicate that the cesponse has been
* output already and processing is complete.
*/
public String handleRequest(HttpServletRequest request, HttpServletResponse response)
{
request.setAttribute("temp","manish");
return "choice.jsp";
}
}
can i anybody tell the reason of this problem
and one more thing
right now i have hard coded the values in hash map
handlerHash.put("/resources/choice.jsp",new handlerpkg.Initialization());
so this controller servlet is still application dependant . can anybody suggest me any way to make it independant of application with an examplee
manish