Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Narendhiran Nagarajan

Ranch Hand
+ Follow
since Jun 17, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Narendhiran Nagarajan

No you cant create a session llike that. You create like
1. HttpSession session = request.getSession();
2. HttpSession session = request.getSession(true);
3. HttpSession session = request.getSession(false);

Note: 1 and 2 are same.But 3 will not create a new session.
For Q17,
I hope, you are saying the answer as F, cause after invalidating the session, we cant access the attributes that are associated with the session.(These all happen at runtime check)
But look carefully at line 16, you cant create a session like this. Thats why its throwing the compilation error.
For Q15,
The HttpSessionBinding listners are usually implemented on the attribute classes, which are used to notify when the attribute is added to or removed from the session. When the session is destroyed it implicitly mean that the attributes are removed from that particular session. So, the valueUnbound method will be called.
Here is the question from the MockUp Exam (JavaBeat)


Given the deployment descriptor for a Web Application is
<web-app version="2.4">
<servlet>
<servlet-name>InitParamsServlet</servlet-name>
<servlet-class>scwcd14.chap02.InitParamsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InitParamsServlet</servlet-name>
<url-pattern>/InitParamsServlet</url-pattern>
<init-param>
<param-name>name</param-name>
<param-value>javabeat</param-value>
</init-param>
</servlet-mapping>
</web-app>
What will be the output of the following Servlet?
package scwcd14.chap02;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class InitParamsServlet extends HttpServlet {
public void init(){
ServletConfig config = getServletConfig();
System.out.println(config.getInitParameter("name"));
System.out.println(config.getInitParameter("no-name"));
}
...
}
a. The Servlet will output 'javabeat null' in the Server Console.
b. The Servlet will fail to load as the init param property 'no-name' is not mentioned in
the deployment descriptor.
c. A NullPointerException will be raised as calling getServletConfig() in the init()
method will return a null reference.


The answer is A.
How?
Thanks.
But if it is placed under the root directory, it can be accessed by any clients directly.
What if i want to restrict the access from the clients.

When you deploy static HTML and JSPs, you can choose whether to make them
directly accessible from outside the web app. By directly accessible, we mean that a
client can enter the path to the resource into his browser, and the server will return
the resource. But you can prevent direct access by putting files under WEB-INF or, if you’re deploying as a WAR file, under META-INF.
- Ref HFSJ

Can this be applied to Images?
When deploying an apllication, where does the jpg files should go?
<servlet>
<servlet-name>InitParamsServlet</servlet-name>
<servlet-class>scwcd14.chap02.InitParamsServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>InitParamsServlet</servlet-name>
<url-pattern>/InitParamsServlet</url-pattern>
<init-param>
<param-name>name</param-name>
<param-value>javabeat</param-value>
</init-param>

</servlet-mapping>

Is it correct?
Can we declare the servlet config parameters inside the <servlet-mapping> tag?
Can you post the class
foo.DiceRoller
The compiler will check whether the local variable is initialized before it is used.
So, if you use the "IF statement"(only) and you are initializing the local variable inside the block.
The compiler does not know whether the block will run or not. So, the compiler is uncertain about the initialization of the local var and it will not compile.

But , if you use "IF ELSE statement" and you are initializing the local variable inside both the block(If and Else).
Then the compiler realises that either one of the statement will run for sure and the var will be initialized before its gonna be used.

1)We know in first request in include standard action a runtime request is going to the header jsp which it complile and become a servlet. So what hapen in the second runtime request for the header jsp. Is it just allocate the thread already created header file servlet or is it do the whole header compilation thing again?
The include directive inserts the SOURCE of “Header.jsp”, at translation time.
But the <jsp:include /> standard action inserts the RESPONSE of “Header.jsp”, at runtime.
[Source: HFSJ]

The include directive gets compiled only once(On first Request).
But the include standard action gets compiled for every Request.

I m not clear with your second ques.Can you rephrase it.
Thanks for all your replies.
But I m sorry to ask the same question again.

Eventhough we can propagate Uncaught checked Exceptions, it should be handled before the main method moves out of the stack.

"So, In which situation the checked Exceptions are thrown from the main method? "
I mean, the till the end of stack(Main method).

I see that, we have to handle the checked exceptions.
Yes ,I agree.

Also, I understand that we can throw checked Exceptions fro main method

In which situation
the checked Exceptions are thrown from the main method.? (main method is the last chance to handle the chk excep)
But my ques is

"Is there any rule like- we need to handle checked exceptions before the completion of the code? "
Should a checked exception be handled before the completion of the code?

As we know, the checked exceptions can be handled(try catch) or declared(throws).

For egs,

Class A{

public static void main(String[] args)
{
try{ m1();
}
catch(Exception e){ }
}
void m1() throws Exception{
m2();
}
void m2() throws Exception{
throw new Exception();
}

}

In this egs, I have handled the Exception in the main method.
If I m not handling, Is it possible throw the Exception in the main method???

public static void main(String[] args) throws Exception
{
m1();
}