• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I can't take it! You are too smart for me! Here is the tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic