Unless you specify the page directive isThreadSafe to be 'false', the JSP
context will create only one instance per page (for all threads to use), so
if one thread changes an instance variable, all threads will see the same
value.  If you specify isThreadSafe to be 'false', each thread will get its
own instance for the page and therefore its own copy of the instance
variables.  This isn't very efficient, though, obviously.  Consider that if
you did it on a Logon page, every user trying to logon would create a new
instance of the Logon.jsp- yikes.

-----Original Message-----
From: Frank Apap [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 15, 2000 2:45 PM
To: [EMAIL PROTECTED]
Subject:


Hi, I am a little curious what you mean about the <%! tag.  I am currently
using it and want to make sure I am not using it incorrectly.  In what cases
would it be a problem.  I am now using it to declare my variables, so are
you saying that if 1 user loads a jsp and the variable declared is set to
something if another user loads the page he can change user1's variable? Im
a little confused.

- Frank
----- Original Message -----
From: Hans Bergsten <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 15, 2000 2:51 PM


> "Wasetis, Ken" wrote:
> >
> > Or define it within <%! and %> tags which should make it an instance
> > variable in the generated servlet.
>
> That's a dangerous solution; since <%! ... %> creates an instance
variable,
> the variable is shared by all threads (i.e. all concurrent accesses to the
> page). In this case the variable value depends on request data, so if you
> use an instance variable concurrent requests will overwrite each others
> values.
>
> A better solution here would be to develop a bean that has a write
> access property named "selComputers" (set from the request parameter
> with the same name using <jsp:setProperty>) and read-only properties
> named "computerName" and "computerDescription". Then all code can be
> replaced with action elements:
>
>   <jsp:useBean id="compInfo" class="com.mycomp.SomeClass" >
>     <jsp:setProperty name="compInfo" property="*" />
>   </jsp:useBean>
>
>   <jsp:getProperty name="compInfo" property="computerName" />
>   <jsp:getProperty name="compInfo" property="computerDescription" />
>
> Hans
>
> > -----Original Message-----
> > From: Vin Lisciandro [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, May 15, 2000 12:28 PM
> > To: [EMAIL PROTECTED]
> > Subject:
> >
> > The compiler is not able to determine that 'myComputerName' will exist
> > because you only instantiate it inside of an IF statement
> >
> > you should do a:
> > String myComputerName = new String();
> > outside of your IF so that the object is brought into scope, then
> > just perform a value assignment inside the IF
> > myComputerName = myComputer.getComputerName();
> >
> > That way there will always be a 'myComputerName' object to satisfy the
> > compiler.
> >
> > - vin
> >
> > At 10:02 AM 5/15/00 -0700, you wrote:
> > >Ok.  So in my JSP I call on a servlet that returns data to me via a
> > >"Computer" object which has name and description properties, but I
can't
> > >seem to get to those properties once I'm back in my JSP.  The jsp code
is
> > >this:
> > ><%
> > >         if (request.getParameter("selComputers") != null) {
> > >                 String getComputer =
request.getParameter("selComputers");
> > >                 net.authentix.applicationdefs.Computer myComputer =
> > >clsGetComputers.compGetAComputer(getComputer);
> > >                 String myComputerName = myComputer.getComputerName();
> > >                 String myComputerDescription =
> > >myComputer.getComputerDescription();
> > >         }
> > >%>
> > >
> > >It is called in a file that get's included only if
> > >request.getParameter("selComputers") exists.
> > >But, if later in the same jsp I reference <%=myComputerName%> I receive
> > this
> > >error
> > >
> > >
> > >
> > >
> > >
> >
>d:\InetPub\ServletExec\ISAPI\Servlets\pagecompile\_AprilRelease\_AdminFunct
> > i
> > >ons\_System\_Services\_console_xjsp.java:189: Undefined variable:
> > >myComputerName
> > >         out.print( String.valueOf(  myComputerName  ) );
> > >                                         ^
> > >Is this a common or obvious error?  It has me quite stumped.
Admittedly I
> > >am a COM/VB dll web programmer trying to learn jsp but I just want to
> > access
> > >the properties of my object.  Is this possible in my jsp?
> > >I wouldn't ask but I've been trying for a couple days now and cannot
get
> > >there.
> > >Thanks.
> > >Jt.
>
> --
> Hans Bergsten           [EMAIL PROTECTED]
> Gefion Software         http://www.gefionsoftware.com
>
>
===========================================================================
> 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
>

===========================================================================
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

===========================================================================
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

Reply via email to