Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic