• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JSP and Path related Question

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from HFSJ page 424.
Question: The following code fragment appears in a JSP page:
<jsp:include page="/jspf/header.html" />
The JSP page is part of a web application with the context root myapp.
Given that the application's top level directory is myapp, what is the path to the header.html file?

A. /header.html
B. /jspf/header.html
C. /myapp/jspf/header.html ....according to the book - correct answer.
D. /includes/jspf/header.html

What I don't understand is the question itself. When it says "what is the path ...", my question is related to what? the server root? or as it would be identified in <location> as defined in web.xml (then the correct answer would be B not C).
Thus, what is the context of the question? or am I missing something that is obvious?

Thanks.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question is just asking what is the path as in the "file path"
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a back slash is present it is considered relative to the current context root. Here the current context root is "myapp"

The server interprets a relative URL relative to the current directory. Here the current directory is "/jspf/header.jsp"

<jsp:include page="/jspf/header.jsp" />

And final answer is:
<%-- Includes: /myapp/jspf/header.jsp --%>
[ December 02, 2005: Message edited by: Vishnu Prakash ]
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the relative URL starts with /, the path is relative to the JSP application's context, If the relative URL starts with a directory or file name, the path is relative to the JSP page.
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic