• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is it a valid jsp code

 
trupti nigam
Ranch Hand
Posts: 626
  • Mark post as helpful
  • send pies
  • 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
 
milind gadgil
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Hafizur Rahman
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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.
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • 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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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)
{}
}
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic