Hi all,
Sorry to post this on the list, but I feel some of you who may have been
following the discussion Craig, Daniel and I have been having might still
like to follow along.
So, I have the controller servlet working. A few questions have arised to a
few posts I have seen you reply to.
First, how do you use a Hashtable? If you already replied to this..my
apologies. I found out my email program was on all weekend in a crashed
state and I lost alot of email, nor could I get any, nor could I send. I
recall you and Daniel both mentioning something about using a Hashtable as a
lookup table (that could be loaded in from a database or a properties file,
or xml file..whatever persistence desired) to figure out the action class to
call?
Next, about the threading issues. I talked to one of our developers here, a
pro with threading, and showed him my bit of code. He concurred with me that
what I am doing "should" be thread safe. Basically, the ControllerServlet,
by using the .newInstance() call, it creates a NEW action class for each
request coming in. Because of this, fields of the class are ok to use on a
per thread/request basis. You might have meant this in your explanation and
I just wasn't clear. I did notice you also mentioned if the action class
uses a bean, multiple requests "could" cause thread problems there if the
bean contained instance fields as well. But again, the action class should
normally create this bean...a new instance again, and place it in the
REQUEST object. If this is the case, is there any reason to worry about
threading issues?
So, if in my action class, I do something like:
public void perform(HttpServletRequest req)
{
// do some logic
...
// create bean
MyBean bean = new MyBean();
bean.setXXX(..);
bean.setYYY(..);
req.setAttribute("MyBean", bean);
setUrl("/forwardToThisPage.jsp");
}
Now, this is "close" to what I expect to have my action classes do. They
figure out logic, create a new bean, populate it, set the forwarding url,
and return back to the controller servlet, which then forwards to the proper
JSP page depending on the setUrl() call in the action class or if an error
occurs.
So, based on the above, isn't my bean thread-safe as well because its a NEW
created object for each request? I agree with Daniel in that everything
should be put in the request scope. When using Model 2, you already are
forced to write the code that gets all the form parameters out of the
request object when it comes in (part of the action class I
believe..right?), and thus, by populating the bean and putting it in the
request, the JSP page will most likely use the bean at the request scope,
fill in the values of another form (or possibly the same form if say an
error occured and the page is being redisplayed) so that a subsequent
request will contain those values where need be.
Alrighty..thats it. Trying to keep these short. Hopefully my above
explaination of why I think its thread-safe is accurate, but please
elaborate on why it is/isn't good design/bad design, if its thread safe,
etc. Also, if you could, is this basically what you are doing (and you too
Daniel if you read this)? Keep in mind I am creating a simple (at this time)
but definitely deployable working Model 2 layout that I should be able to
use with other web applications, but that does indeed work with security,
user-roles (whatever the heck these are), and does the job as you guys use
it.
Thanks so much for all of your emails. I know its taught me alot and
enlightened me on a number of topics I was unclear about. I hope its doing
the same for others reading this ongoing discussion.
Take care.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets