aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Mock exam tricky questions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mock exam tricky questions?" Watch "Mock exam tricky questions?" New topic
Author

Mock exam tricky questions?

madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
Hi i have taken free mock exam of JwebPlus


Your servlet may receive a request which it cannot handle. In such cases, you want to redirect the request to another resource which may or may not be a part of the same webapplication. Which of the following options can be used to achieve this objective?
1.
RequestDispatcher rd = this.getServletContext().getRequestDispatcher("some url");
rd.forward(request, response);

2.
RequestDispatcher rd = request.getRequestDispatcher("some url");
rd.forward(request, response);

3. response.sendRedirect("some url");

4. request.sendRedirect("some url");

what would the answer?

my answer was none of the above..
but the answer is response.sendRedirect("some url"); how could it be.. if the url specify the out of web app.. will it be right?

could anyone justify the answer..

Another question

By Implementing SingleThreadModel interface doesnot ensure Your servlet is threadsafe.. ? How could you justify the above..




ThanksIn advance..


saivenumadhav
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Madhav,

For the first question... i have a question in reply!

Consider you are running a real web application.
and your context root has been modified say in the same server.

How you tackle the change. I mean How you are gonna inform old users ???
Hope this will answer your first question.


[ March 08, 2007: Message edited by: Srinivasan thoyyeti ]

Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
which may or may not be a part of the same webapplication


Hi srinivas thanks for your answer, I know response.sendRedirect is one possible answer. (consider url is part of the same webapplication) ..

If it is not part of the same webapplication then,,,, response.sendRedirect will work..?

Regards
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Madhav,

Within the Same WebServer (say Tomcat, if you have two web applications.)

1) webAppl1 //currently used
welcome.jsp

2) webAppl2
welcomeNew.jsp

you want to make used welcomeNew.jsp(webappl2) instead of welcome.jsp(webappl1).
it can be done with this:
welcome.jsp:
<%
response.sendRedirect("htp://localhost:8080/webappl2/welcomeNew.jsp");
%>

Let user invoke the same URL: http://localhost:8080/weappl1/welcome.jsp

Hope it is much more clear.
H Pathak
Greenhorn

Joined: Dec 20, 2006
Posts: 28
1. response.sendRedirect() returns a redirect message to the browser, with a "location" header that specifies url to go to. The url in the location header can be any other url (e.g. "http://www.yahoo.com") or it can be just the change in the protocol (using https instead of http). So, response.sendRedirect() can ask the client browser to any other url also.

2. if your servlet implements single thread model, container ensures that only one thread of a servlet instance will be running the service() method. But this does not ensure safety, as the following examples state:

(A) What if two different servlets access the same session or application level variable? Even if the two different servlets are running in seperate threads, BOTH THE THREADS HAVE ACCESS TO THE ServletContext OBJECT!!!

(B) Declare a servlet class MyServlet, and let it have a static member myStatic. Now, declare two servlet elements in the DD, such that both servlet elements use the MyServlet class. In this case, container will create 2 instances of MyServlet class, one for each servlet element in the DD. Even though these two servlets are running in seperate threads, still they can simultaneously access the common static member myStatic, as it is at the class level


SCJP 1.4 - cleared<br />SCWCD 1.4 - cleared!!
madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
hi

thanks guys

nice explanation given by patak..
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

So that means a RequestDispatcher cannot reach out of the web app? Am I right guys?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
yeah jyothi
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Thanks Madhav!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock exam tricky questions?