1) It won't compile. 2) It is a valid jsp line and it will print the variable called name. 3) It will compile but it will always produce null as the output. 4) It will work if you create a javabean class with only one variable of type java.lang.String.
The answer in the mock exam was 2) . How is this possible??
You are right. I find it confusing too since the java.lang.String class does now have an implementation to get the value for variable "name". I am not sure from where will it get the value of the variable 'name'.
so now what would be the output of <jsp:useBean id=”name” class=”java.lang.String” /> <%= akshay? %>
as simple as that, the exam does a lot of playing on variable names and strings, and the first part in passing it obviously to see through all these tricks
You are wrong, or my container is wrong. It will not output akshay, there will be an error, unless you put it inside the quotes.
Answer 2 is correct. Having this code:
There are three possibilities.
1). Attribute "name" exists in page scope. 2). Attribute "name" exists in any scope other than page scope. 3). Attribute "name" doesn't exist at all.
Then what happens:
1). <jsp:useBean> will use this attribute, expression will evaluate to the value of the attribute 2). <jsp:useBean> will create bean and we'll get blank page 3). <jsp:useBean> will create bean and we'll get blank page
This is how it work in my container. I'm also wondering why it doesn't print null in 2) and 3), just there's a blank page.