Re: how to implement a front controller?

Juan Salazar <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Organization Merkafon
Message-ID <[email protected]>
are you looking for a MVC (Model-View-Controller)? See http://jakarta.apache.org/struts/index.html

Maciek Zywno wrote:

hello

I wanted to write a simple front controller.
As for now it is to do nothing else than just take a look inside a request,
check what page a client wants to see and just forward a request to an appropriate
page. Is it possible?

In my web.xml I put mapping for all requests
to be checked by my front controller:

<servlet>

<servlet-name>FrontController</servlet-name>

<servlet-class>frontController</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>FrontController</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>

in doProcess:

String urlTarget = request.getgetPathInfo();

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(urlTarget);

dispatcher.forward( request, response );

when I try to visit any page in my webapp
I get the error

java.lang.ClassCastException
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:243)
.....

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
....

Do you have any idea of what is wrong with my piece of code?

thanks in advance

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.