File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam questions...

 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

This is taken from the mock exams:

Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

public void doGet(HttpServletRequest req, HttpServletResponse res)
{
try{
RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1
rd.forward(req, res); // 2
} catch(Exception e)
{ e.printStackTrace(); }
}

Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
ANS : C,E

My answer should be B, E. Am I wrong?
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find your answer to be right! B and E should be the right ones.
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mani,

But now I have doubt again:

8.Consider the web.xml snippet shown in the exhibit.
Now consider the code for a jsp file named unprotected.jsp:
<html>
<body>
<jsp:include page="/jsp/protected.jsp" />
</body>
</html>
Which of the following statements hold true when unprotected.jsp is requested by an unauthorized user?
<web-app>
...
<security-constraint>
<web-resource-collection>
<web-resource-name>test</web-resource-name>
<url-pattern>/jsp/protected.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>manager</role-name>
</auth-constraint>
</security-constraint>
...
</web-app>
Select 1 correct option.
A.The user will be prompted to enter user name and password
B.An exception will be thrown
C.protected.jsp will be executed but it's output will not be included in the response
D.The call to include will be ignored
E.None of these
ANS : E

I think the answer should be B, because it is attempting to access unauthorized resource. Can someone explain this?
Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic