aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Path Question Doubt As in EnthuWare 5.2.77 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 "Servlet Path Question Doubt As in EnthuWare 5.2.77" Watch "Servlet Path Question Doubt As in EnthuWare 5.2.77" New topic
Author

Servlet Path Question Doubt As in EnthuWare 5.2.77

chandan kumar mitwaa
Ranch Hand

Joined: Jul 01, 2009
Posts: 49
You want only the requests having a servlet path of /report (excluding the query string) to be serviced by ReporterServlet. Which of the following mappings would you use?

A) /report/* mapped to ReporterServlet
B) /report mapped to ReporterServlet

Enthuware Q.Bank says B) is the correct answer and explains:
When /report is mapped to ReporterServlet, all of the following requests will be sent to ReporterServlet:
While the following requests will not be sent to ReporterServlet:
/report/index.html
/report/finance
But if you map /report/* to ReporterServlet, the above two requests will also be sent to ReporterServlet.


But it is also true for the case A) that all the requests to this mapping will have the servlet path /report and would be sent to ReporterServlet

Is A) is a correct answer too?






Thanks,
Chandan Kumar
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

You want only the requests having a servlet path of /report (excluding the query string) to be serviced by ReporterServlet.

The question says that only the requests with /report path should be handled by ReporterServlet...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
chandan kumar mitwaa
Ranch Hand

Joined: Jul 01, 2009
Posts: 49
Ankit,
I have tried for example /report/index.do which also has the servlet path /report for the mapping /report/*. Such requests are a super set of those for the mapping /report.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Yes chandan I agree, if you map a servlet to the path /report/* and a request comes for /report/index.do, the request.getServletPath method will return /report, but I think what the question was trying to say was that only the requests with path /report should be handled. When the question said "servlet path", I think they didn't mean the value returned by the request.getServletPath method (actually "servlet path" means the value returned by request.getServletPath, but I think the question didn't mean that). Anyone from Enthuware might clarify more what the question actually meant...
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368

You want only the requests having a servlet path of /report (excluding the query string) to be serviced by ReporterServlet. Which of the following mappings would you use?

A) /report/* mapped to ReporterServlet
B) /report mapped to ReporterServlet


yes, I think Ankit is right. because they mentioned explicitly "excluding the query string" means after "/report" there is a query string no other path in mapping.

HTH.


Thanks,
Shailesh
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

1)If we map the servlet using
<url-pattern> /report </url-pattern> the servlet path will be /report.

2)If we map the servlet using
<url-pattern> /report/* </url-pattern> the servlet path will be /report


3)If we map the servlet using
<url-pattern> /report/xyz/* </url-pattern> the servlet path will be /report/xyz.

The question is:
You want only the requests having a servlet path of /report (excluding the query string) to be serviced by ReporterServlet. Which of the following mappings would you use?

A) /report/* mapped to ReporterServlet
B) /report mapped to ReporterServlet


If we try to construct the requests having the servlet path of /report , some of the requests would be,
1. http://localhost:8080/contextPath/report (This URl will be served by the server - exact match)
2. http://localhost:8080/contextPath/report?id=1234

If we try to construct the requests having the servlet path of /report /* , the requests would be,
1. http://localhost:8080/contextPath/report/
2. http://localhost:8080/contextPath/report/abc/def/
3. http://localhost:8080/contextPath/report/abc/def/ghi?id=1234 etc. etc.

If we use the mappping as:


A) /report/* mapped to ReporterServlet

the requests,
1. http://localhost:8080/contextPath/report/
and 2. http://localhost:8080/contextPath/report/abc/def/
from above mentioned URLs will be served (excluding the query string).

and for mapping

B) /report mapped to ReporterServlet
the request,
1. http://localhost:8080/contextPath/report will be served (excluding the query string).


So, from the above, both the mappings should work.

Correct me if I am wrong?





SCJP 1.4, SCWCD 5
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3314
    
    8
Hi,
Ankit is right. The question should be made clearer to avoid confusion caused by the words "servlet path". The intention is to only allow requests having a complete path (excluding query string) to be serviced by the servlet. So /report is the correct answer.

An appropriate change has been in the question.

thank you,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi,


Yes, if servlet path is replaced by complete path, the correct option will be B) /report mapped to ReporterServlet .


Thanks,
Nitin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Path Question Doubt As in EnthuWare 5.2.77