You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peng Tuck Kwok <pe...@makmal.net> on 2003/02/11 07:06:02 UTC
Some questions about struts
I have a few questions I need to ask about struts. First of I've done
some simple examples that allow my struts example to access the database
and validate fields passed by an action form. All is good and well.
Now I want my application to read say two xml files and when a page is
requested, the page would display the data from the xml.
My question is when I pre-process the xml file on startup, how do I make
the xml data available to struts on startup? Should I use a
ActionServlet to do this ? Or am I barking up the wrong tree here?
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by Peng Tuck Kwok <pe...@makmal.net>.
Yes, I did notice that they used struts which was also the reason I
poked around there in the first place hoping to learn a thing or two :) .
Craig R. McClanahan wrote:
>
>
>
> The server.xml file is read by the org.apache.catalina.startup.Catalina
> class - see the createStartDigester() method for where it sets up all the
> processing rules. This is invoked before any of the webapps are actually
> enabled. The web.xml file for a particular web application (along with
> the default configuration file $CATALINA_HOME/conf/web.xml) is read in
> the org.apache.catalina.startup.ContextConfig class -- see the
> defaultConfig() and applicationConfig() methods. The Digester rules are
> set up in createWebDigester(). This happens at one of several times:
> * At startup time, when a <Context> element is found in web.xml
> * At startup time, when a directory, WAR file, or XML file is
> found in the "webapps" directory
> * While Tomcat is running, if a new WAR or directory is added
> to the "webapps" directory
> * While Tomcat is running, if you use the Manager webapp's
> "install" or "deploy" commands.
>
> The Tomcat admin webapp knows how to write back out to server.xml, but it
> doesn't actually *read* that file. Instead, it uses an API called Java
> Management Extensions (JMX) to manage the configuration of all the
> internal components of Tomcat itself. In Tomcat 4.1, the JMX layer is
> basically added on top of the existing Catalina architecture, so about the
> only thing it does is manipulate the configuration in response to admin
> webapp changes. In Tomcat 5, JMX will be used much more aggressively --
> not only for configuration management, but also for things like statistics
> gathering. It should be straightforward for JMX-enabled management tools
> to easily configure and manage one or more Tomcat 5 installations.
>
> If you look at the sources for the admin webapp, you will also note, of
> course, that the developers were pretty smart -- they used Struts to build
> this app :-).
>
> Craig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 11 Feb 2003, Peng Tuck Kwok wrote:
> Yes it is very cool and nice to use :) . I've done some simple things
> with it based on a tutorial I followed from the site. One question
> though, I've been poking around the admin webapp source in tomcat, which
> file actually reads the server.xml? Or is the contents of server.xml
> already made available to the webapp?
The server.xml file is read by the org.apache.catalina.startup.Catalina
class - see the createStartDigester() method for where it sets up all the
processing rules. This is invoked before any of the webapps are actually
enabled. The web.xml file for a particular web application (along with
the default configuration file $CATALINA_HOME/conf/web.xml) is read in
the org.apache.catalina.startup.ContextConfig class -- see the
defaultConfig() and applicationConfig() methods. The Digester rules are
set up in createWebDigester(). This happens at one of several times:
* At startup time, when a <Context> element is found in web.xml
* At startup time, when a directory, WAR file, or XML file is
found in the "webapps" directory
* While Tomcat is running, if a new WAR or directory is added
to the "webapps" directory
* While Tomcat is running, if you use the Manager webapp's
"install" or "deploy" commands.
The Tomcat admin webapp knows how to write back out to server.xml, but it
doesn't actually *read* that file. Instead, it uses an API called Java
Management Extensions (JMX) to manage the configuration of all the
internal components of Tomcat itself. In Tomcat 4.1, the JMX layer is
basically added on top of the existing Catalina architecture, so about the
only thing it does is manipulate the configuration in response to admin
webapp changes. In Tomcat 5, JMX will be used much more aggressively --
not only for configuration management, but also for things like statistics
gathering. It should be straightforward for JMX-enabled management tools
to easily configure and manage one or more Tomcat 5 installations.
If you look at the sources for the admin webapp, you will also note, of
course, that the developers were pretty smart -- they used Struts to build
this app :-).
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Some questions about struts
Posted by Jacob Hookom <ho...@uwec.edu>.
Yeah, digester is sooo neat that I use it to brush my teeth at night.
-Jacob ;-)
| -----Original Message-----
| From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
| Sent: Tuesday, February 11, 2003 1:28 AM
| To: Struts Users Mailing List
| Subject: Re: Some questions about struts
|
| Craig R. McClanahan wrote:
| >>
| > Digester is pretty cool (if I do say so myself :-). It's what Struts
| uses
| > to process struts-config.xml files, and what Tomcat uses to read web.xml
| > and server.xml files.
| Yes it is very cool and nice to use :) . I've done some simple things
| with it based on a tutorial I followed from the site. One question
| though, I've been poking around the admin webapp source in tomcat, which
| file actually reads the server.xml? Or is the contents of server.xml
| already made available to the webapp?
|
| I will check out the commons digester api in further detail.
|
| >
| > The Javadocs are also available online:
| >
| > http://jakarta.apache.org/commons/digester/api/
| >
| > In particular, read the "Package Description" which has a good overview
| of
| > how Digester can be used.
| >
| > Finally, the COMMONS-USER mailing list is a good place for general
| > questions on Digester that aren't Struts related.
| >
| > Craig
| >
| > ---------------------------------------------------------------------
| > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| > For additional commands, e-mail: struts-user-help@jakarta.apache.org
| >
| >
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by Peng Tuck Kwok <pe...@makmal.net>.
Craig R. McClanahan wrote:
>>
> Digester is pretty cool (if I do say so myself :-). It's what Struts uses
> to process struts-config.xml files, and what Tomcat uses to read web.xml
> and server.xml files.
Yes it is very cool and nice to use :) . I've done some simple things
with it based on a tutorial I followed from the site. One question
though, I've been poking around the admin webapp source in tomcat, which
file actually reads the server.xml? Or is the contents of server.xml
already made available to the webapp?
I will check out the commons digester api in further detail.
>
> The Javadocs are also available online:
>
> http://jakarta.apache.org/commons/digester/api/
>
> In particular, read the "Package Description" which has a good overview of
> how Digester can be used.
>
> Finally, the COMMONS-USER mailing list is a good place for general
> questions on Digester that aren't Struts related.
>
> Craig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 11 Feb 2003, Peng Tuck Kwok wrote:
> Date: Tue, 11 Feb 2003 14:53:33 +0800
> From: Peng Tuck Kwok <pe...@makmal.net>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: Some questions about struts
>
> Jacob Hookom wrote:
> > As a side note, look at Commons Digester in reading your XML file and
> > bringing it in as Objects so you can work with ActionForms and other
> > business logic (if that's what you want to do).
> >
>
> Yes I do intend to use the Commons Digester. Thanks Jacob.
>
Digester is pretty cool (if I do say so myself :-). It's what Struts uses
to process struts-config.xml files, and what Tomcat uses to read web.xml
and server.xml files.
The Javadocs are also available online:
http://jakarta.apache.org/commons/digester/api/
In particular, read the "Package Description" which has a good overview of
how Digester can be used.
Finally, the COMMONS-USER mailing list is a good place for general
questions on Digester that aren't Struts related.
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by Peng Tuck Kwok <pe...@makmal.net>.
Jacob Hookom wrote:
> As a side note, look at Commons Digester in reading your XML file and
> bringing it in as Objects so you can work with ActionForms and other
> business logic (if that's what you want to do).
>
Yes I do intend to use the Commons Digester. Thanks Jacob.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Some questions about struts
Posted by Jacob Hookom <ho...@uwec.edu>.
Usually in this case, you use the unit of work pattern and the lazy load. I
usually handle it like so:
public class UserData
{
private final static Object _lock = new Object();
private ServletContext context;
private int state;
private String path;
private UserData(ServletContext context, String path)
{
this.context = context;
this.path = path;
}
public void registerNew() throws Exception
{
// do your parsing based on context
this.state = CLEAN;
}
public static UserData getInstance(ServletContext context, String file)
throws Exception
{
String key = genContextKey(file);
UserData userData = (UserData) context.getAttribute(key);
if (userData == null)
{
// make sure we don't create multiple copies
synchronized(_lock)
{
// double check that a previous thread didn't
// already make one right before me
userData = (UserData) context.getAttribute(key);
if (userData == null)
{
// create a new one
userData = new UserData(context, file);
userData.registerNew();
// now store it for other threads
context.setAttribute(key, userData);
}
}
}
return userData;
}
}
in your action then:
UserData userData = UserData.getInstance(context, "somefile.xml");
Collection employees = userData.getAllEmployees();
userData.addEmployee(new Employee("Craig"));
userData.registerClean();
As a side note, look at Commons Digester in reading your XML file and
bringing it in as Objects so you can work with ActionForms and other
business logic (if that's what you want to do).
-Jacob
| -----Original Message-----
| From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
| Sent: Tuesday, February 11, 2003 12:25 AM
| To: Struts Users Mailing List
| Subject: Re: Some questions about struts
|
| Thanks for the prompt reply Jacob.
| I do need the xml data to persist, one xml which contains a bunch of
| users who can log in & the other xml contains a list of numbers that
| belong to the bunch of users.
| Since I need the application to read these xml files on startup, does
| that mean I need to create a class which extends ActionServlet and
| populate the servlet context like this ? :
| getServletContext().setAttribute(LOCALES_KEY, locales);
|
|
|
|
|
|
| Jacob Hookom wrote:
| > You can have the ActionServlet determine where the source XML is coming
| > from. Then, either forward to a JSP and use JSTL to handle the
| rendering,
| > or use a transformer and write directly to the OutputStream within the
| > ActionServlet, and return null instead of an ActionForward.
| >
| > -Jacob
| >
| > | -----Original Message-----
| > | From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
| > | Sent: Tuesday, February 11, 2003 12:06 AM
| > | To: Struts Users Mailing List S
| > | Subject: Some questions about struts
| > |
| > | I have a few questions I need to ask about struts. First of I've done
| > | some simple examples that allow my struts example to access the
| database
| > | and validate fields passed by an action form. All is good and well.
| > |
| > | Now I want my application to read say two xml files and when a page is
| > | requested, the page would display the data from the xml.
| > | My question is when I pre-process the xml file on startup, how do I
| make
| > | the xml data available to struts on startup? Should I use a
| > | ActionServlet to do this ? Or am I barking up the wrong tree here?
| > |
| > |
| > |
| > |
| > | ---------------------------------------------------------------------
| > | To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| > | For additional commands, e-mail: struts-user-help@jakarta.apache.org
| >
| >
| > ---------------------------------------------------------------------
| > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| > For additional commands, e-mail: struts-user-help@jakarta.apache.org
| >
| >
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by Rajan Gupta <rg...@yahoo.com>.
How about writing a Servlet which is loaded on Startup & configured as
such in web.xml. This servlet can load the data from the files & store
them in a responsible context
--- Peng Tuck Kwok <pe...@makmal.net> wrote:
> Thanks for the prompt reply Jacob.
> I do need the xml data to persist, one xml which contains a bunch of
> users who can log in & the other xml contains a list of numbers that
> belong to the bunch of users.
> Since I need the application to read these xml files on startup, does
> that mean I need to create a class which extends ActionServlet and
> populate the servlet context like this ? :
> getServletContext().setAttribute(LOCALES_KEY, locales);
>
>
>
>
>
>
> Jacob Hookom wrote:
> > You can have the ActionServlet determine where the source XML is
> coming
> > from. Then, either forward to a JSP and use JSTL to handle the
> rendering,
> > or use a transformer and write directly to the OutputStream within the
> > ActionServlet, and return null instead of an ActionForward.
> >
> > -Jacob
> >
> > | -----Original Message-----
> > | From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
> > | Sent: Tuesday, February 11, 2003 12:06 AM
> > | To: Struts Users Mailing List S
> > | Subject: Some questions about struts
> > |
> > | I have a few questions I need to ask about struts. First of I've
> done
> > | some simple examples that allow my struts example to access the
> database
> > | and validate fields passed by an action form. All is good and well.
> > |
> > | Now I want my application to read say two xml files and when a page
> is
> > | requested, the page would display the data from the xml.
> > | My question is when I pre-process the xml file on startup, how do I
> make
> > | the xml data available to struts on startup? Should I use a
> > | ActionServlet to do this ? Or am I barking up the wrong tree here?
> > |
> > |
> > |
> > |
> > |
> ---------------------------------------------------------------------
> > | To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > | For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Some questions about struts
Posted by Peng Tuck Kwok <pe...@makmal.net>.
Thanks for the prompt reply Jacob.
I do need the xml data to persist, one xml which contains a bunch of
users who can log in & the other xml contains a list of numbers that
belong to the bunch of users.
Since I need the application to read these xml files on startup, does
that mean I need to create a class which extends ActionServlet and
populate the servlet context like this ? :
getServletContext().setAttribute(LOCALES_KEY, locales);
Jacob Hookom wrote:
> You can have the ActionServlet determine where the source XML is coming
> from. Then, either forward to a JSP and use JSTL to handle the rendering,
> or use a transformer and write directly to the OutputStream within the
> ActionServlet, and return null instead of an ActionForward.
>
> -Jacob
>
> | -----Original Message-----
> | From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
> | Sent: Tuesday, February 11, 2003 12:06 AM
> | To: Struts Users Mailing List S
> | Subject: Some questions about struts
> |
> | I have a few questions I need to ask about struts. First of I've done
> | some simple examples that allow my struts example to access the database
> | and validate fields passed by an action form. All is good and well.
> |
> | Now I want my application to read say two xml files and when a page is
> | requested, the page would display the data from the xml.
> | My question is when I pre-process the xml file on startup, how do I make
> | the xml data available to struts on startup? Should I use a
> | ActionServlet to do this ? Or am I barking up the wrong tree here?
> |
> |
> |
> |
> | ---------------------------------------------------------------------
> | To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> | For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Some questions about struts
Posted by Jacob Hookom <ho...@uwec.edu>.
You can have the ActionServlet determine where the source XML is coming
from. Then, either forward to a JSP and use JSTL to handle the rendering,
or use a transformer and write directly to the OutputStream within the
ActionServlet, and return null instead of an ActionForward.
-Jacob
| -----Original Message-----
| From: Peng Tuck Kwok [mailto:pengtuck@makmal.net]
| Sent: Tuesday, February 11, 2003 12:06 AM
| To: Struts Users Mailing List S
| Subject: Some questions about struts
|
| I have a few questions I need to ask about struts. First of I've done
| some simple examples that allow my struts example to access the database
| and validate fields passed by an action form. All is good and well.
|
| Now I want my application to read say two xml files and when a page is
| requested, the page would display the data from the xml.
| My question is when I pre-process the xml file on startup, how do I make
| the xml data available to struts on startup? Should I use a
| ActionServlet to do this ? Or am I barking up the wrong tree here?
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org