This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Can we use multiple Controllers in a single web-application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Can we use multiple Controllers in a single web-application?" Watch "Can we use multiple Controllers in a single web-application?" New topic
Author

Can we use multiple Controllers in a single web-application?

Amith Mahalingaiah
Greenhorn

Joined: Jul 12, 2004
Posts: 7
hi,

i have a requirement where we need to use two Controllers (one for each module) in our project.

my web.xml looks like this..........

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>controller1</servlet-name>
<servlet-class>com.test.struts.Controller1</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/config1.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet>
<servlet-name>controller2</servlet-name>
<servlet-class>com.test.struts.Controller2</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/config2.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>controller1</servlet-name>
<url-pattern>/controller1/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>controller2</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</web-app>

..both controller1 and controller2 extend ActionServlet. when using controller2 i use the URL
http://localhost:9080/MultipleControllers/Welcome.do

(the struts-config snippet corresponding to Welcome.do is shown below
)

<action

path="/Welcome"

type="org.apache.struts.actions.ForwardAction"

parameter="/pages/Welcome.jsp"/>


and it works fine.....next i want to use the controller1 and i use the url

http://localhost:9080/MultipleControllers/controller1/WelcomePage

(the struts-config snippet corresponding to "WelcomePage" is shown below
)
<action

path="/WelcomePage"

type="org.apache.struts.actions.ForwardAction"

parameter="/WorkFlow/pages/WorkFlowWelcome.jsp"/>


..now it gives me an error

org.apache.struts.action.RequestProcessor Invalid path /WorkFlow/WelcomePage was requested

i dont know why this error comes up.

i also wanted to clear some of my doubts connected with the same.

1)Is it possible to have Multiple Controllers in a single web-applicaion?
(both these controllers are extended from the ActionServlet)

2)if Yes, can you please post some sample code which would help me in understanding the same?

3)Can this Muliple Controller concept be used along with the struts modules?
(or to rephrase...Can the struts modules concept work with more than one Controller?)

I am stuck with this for quite some time. If any of you have faced similar situations...please guide me or help me with some code snippets.

THanks in advance
-AMith
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we use multiple Controllers in a single web-application?