aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes is it a valid jsp code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "is it a valid jsp code" Watch "is it a valid jsp code" New topic
Author

is it a valid jsp code

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Oct 21, 2002
Posts: 11
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

Joined: Sep 05, 2002
Posts: 98
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.


SCJP 2(94%), SCBCD 5.0(86%), SCDJWS(86%), SCEA 5 (I-73%, II/III-88%)
The illiterate of the 21st century will not be those who cannot read and write, but those who cannot learn, unlearn, and relearn. - Alvin Toffler
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
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

Joined: Feb 27, 2002
Posts: 8919

First one is valid. The initializer block is called when the servlet instance (compiled from jsp) is created.


Groovy
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
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

Joined: Jun 25, 2002
Posts: 104
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 ]

SCEA | SCBCD | SCWCD | SCJP - The kSpace
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is it a valid jsp code