• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using RequestDispatcher with <c:url> tag

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kindly please explain bold thing with an example:

Q1 ) How we can use RequestDispatcher with <c:url> tag?

Q2) How <c:import> comes into picture?

Q3) Why we need to remove session ID information?



Which of the following statements about the <c:url> core tag are true? Select three choices.

Choose at least one answer.
a. This tag can be applied to both absolute and relative URLs.
b. This tag performs URL rewriting for any kind of URLs.
c. Encoding of special characters is taken care of.
d. Specifying a URL in a foreign context is possible through the context attribute.
e. The URL created by this tag may fail when used in a RequestDispatcher call.


Choices A, D, and E are the correct answers.

<c:url> processes a URL and rewrites it if necessary. Although this tag accepts both absolute and relative URLs,
rewriting is done only for the latter. Absolute URLs are not rewritten to prevent situations where an external URL could be rewritten and
expose the session ID. Hence choice A is correct,

while choice B is incorrect.

Specifying a URL in a foreign context is possible through the context attribute. The URL specified must start with a '/' (since this is a context-relative URL). The context name must also start with a '/' (since this is a standard way to identify a context). Hence choice D is correct.
Because the URL built by this action may include session information as a path parameter, it may fail if used with RequestDispatcher of the Servlet API. The consumer of the rewritten URL should therefore remove the session ID information prior to calling RequestDispatcher. This situation is properly handled in <c:import>. Hence choice E is correct.


If the URL contains characters that should be encoded (e.g. space), it is the user's responsibility to encode them. Hence choice C is incorrect.
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amolpalekar please Quote Your Sources when you post a question...
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from whizlabs simulator
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement in bold in your post is from the JSTL spec. The servlet spec doesn't says anything about any problems with using URLs with session ID with RequestDispatcher. I created a sample program to test it after disabling cookies in my browser. I had no problem with the program on tomcat 6

Maybe there is problem in some cases.

PS: when I disabled cookies, my session at javaranch expired and I had to write this text again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic