This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!