File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes let's discuss to implementing multiple controllers by using struts1.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "let Watch "let New topic
Author

let's discuss to implementing multiple controllers by using struts1.0

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello everyone:
i know that the struts1.1beta has supported multiple controllers,but it is still the beta version,till now,nobody mentioned how to implement multiple controllers by using struts1.0,i wonder if i can implement multiple controllers by using struts1.0 as follow:
1 write two empty class,each of them extends "org.apache.struts.action.ActionServlet".
2 register them in the "web.xml" file.
3 assign different properties file and config files to them.
follow is the "web.xml" file:

<?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>scioworks.sample.survey.struts.Controller1</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>scioworks.sample.survey.struts.survey1</param-value>
</init-param>
<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>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>controller2</servlet-name>
<servlet-class>com.jhtop.pim.forum.Controller2</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.jhtop.pim.forum.forum</param-value>
</init-param>
<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>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</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>/controller2/*</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>

after that,you can write you application to use the controllers,but i find that the "controller2" work s well,but the "controller1" can't read the properties file,i mean that when it read the "<bean:message......>" tag,in the jsp page,it throws "missing message for key......" exception.
why?who will like to take a try?and give me your result?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

The problem with using multiple controllers with Struts 1.0 is that there are a number of constructs (mappings, properties and so on) that are stored as attributes of the servlet context.
Since both of the controllers share the same servlet context, whichever loads last replaces the values set by the first.
Probably not what you wanted to hear.
If you want to get into modifying Struts code yourself, you can make this work by replacing the code that stores and retrieves the constructs in the servlet context with code that stores/retrieves these constructs as keyed collections.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
thanks
i know that struts1.1beta version has implemented multiple controller,but i
can't find any sample within its package,how can i do that?or where i can
get the sample about it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: let's discuss to implementing multiple controllers by using struts1.0