• 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

is it a valid jsp code

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)
<%!
Hashtable ht = new Hashtable();
{
ht.put("max", "10");
}
%>
2)
<%!
Hashtable ht = new Hashtable();
ht.put("max", "10");
%>

Is it a valid jsp code?
Need explanation..
Thanks
Trupti
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 is valid bcoz the declaration and then the instance block is valid java code. #
2 is not valid bcoz it should appear in the instance block to be valid.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by milind gadgil:
Good Answers
1 is valid bcoz the declaration and then the instance block is valid java code. #
2 is not valid bcoz it should appear in the instance block to be valid.

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, according to me ,both sholud be valid,if not then u guys need to do a lot of explaining to me.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First one is valid. The initializer block is called when the servlet instance (compiled from jsp) is created.
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK u win but see if the .jsp page is compiled into a java class then shouldnt it be like this------->
public class _whatever
{
Hashtable ht=new Hashtable();
ht.put("new1,"10");
public void service(HttpServletRequest,HttpServletRequest,HttpServletResponse)
{}
}
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it should be like that. That's why it was invalid, because a statement, like ht.put("new1", "10"); cannot exist by itself. Otherwise, you will get compilation error.
[ November 08, 2002: Message edited by: ks wong ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic