• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how does this declaration differs !!!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%!<br /> Connection conn = null %>
and
<% Connection conn = null %>.
Which one should be used....
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what was that??
 
Manishada
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry !! that was surprising !!
Actual doubt is:
This is how I declare my Connection Object
< ! Connection con=null %>
Is this is right ??
<% Connection con=null %>
Pls comment
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first one is an incorrect JSP Declaration and the second one is an incorrect JSP scriptlet. Scriptlets are translated into the service method of the translated servlet, whereas the declaration is translated to the body of the servlet class.
The syntax in the example is incorrect they must both have a semi-colon at the end in order to compile. The declaration will become an instance variable whereas the scriptlet will become a method variable.
Therefore this

would get translated to something like this

So, depending on what you are going to do with the variable, will depend where you put it. But, preferably the option is to put your DB access code somewhere other than the JSP, i.e a JavaBean or EJB.
BTW: You should download and have a look at the JSP specification to see the JSP constructs.
------------------------------------

Originally posted by Manishada:
Sorry !! that was surprising !!
Actual doubt is:
This is how I declare my Connection Object
< ! Connection con=null %>
Is this is right ??
<% Connection con=null %>
Pls comment

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi abhi... i mean manishada,
ur declaration is causing the single connection object to handle mutliple connectivity when the same jsp file is being accessed by concurrent users. this can lead to a prob when the close method is called as the other request won't get the connection and they will be forced to create new connections.
I hope things are clearer now. pl try the same and revert back.
regards,
satya
 
Manishada
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thanx for all those valuable suggestions.
Regards
By the way Mr.Satya what was that abhi i mean manishada !!! needs more clarification
 
satya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't why but instead of writing ur name i was going to write abhilash and then i stopped.. I hope things are clearer now. i hope u will not get a compilation error now.
reply
    Bookmark Topic Watch Topic
  • New Topic