Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fail to include file from upper directory

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just moved server and found this problem below.

Directory structure:
/home/mydomain/public_html/ - index.jsp
- include
- validate.jsp
- member
- login.jsp


Basically I am trying to include validate.jsp from login.jsp

So in login.jsp I wrote:
<%@ include file="/include/validate.jsp"%> // THIS ONE GIVES ERROR
<%@ include file="../include/validate.jsp"%> // ALSO GIVES ERROR
<%@ include file="/../include/validate.jsp"%> // ALSO ERROR

Then I try to do some debugging. I put these line of codes in the login.jsp

application.getRealPath("/")
//Returns: /home/mydomain/public_html/member/


application.getRealPath("../include/validate.jsp")
//Returns: /home/mydomain/public_html/member/../include/validate.jsp

Can anyone tell me how to make this work?

I was even thinking of putting the validate.jsp in all subfolders temporarily. But this one is a rather desperate move. I have many config files in the /home/mydomain/public_html/include/.

Thanks all in advance for the help and time on my request.. Cheers..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.



Honestly, that's horrible when used for images, CSS and JS.

If really needed, I would just set it at one place using <base> tag in the HTML head.
[ December 16, 2008: Message edited by: Bauke Scholtz ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bauke Scholtz:


Honestly, that's horrible when used for images, CSS and JS.

If really needed, I would just set it at one place using <base> tag in the HTML head.

[ December 16, 2008: Message edited by: Bauke Scholtz ]



And if the context path changes, how do you update all of the base tags?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use it in base path?

There's no need to pollute all img/css/js links for that.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, if your application's context path was "abc" and you were accessing it at the domain "xyz.com" with:
http://www.xyz.com/abc

How would you build links to your css sheets and JS pages?


Then, what if you needed a test copy with a context path of "abctest"?
How would you update the links?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not needed. Set it in base path.

http://www.w3.org/TR/html401/struct/links.html#h-12.4
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's not needed and (in the case above) what would you set the base path to?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I avoid the base tag for reasons I will not go into here because this topic is about the include mechanism, not client-requested resources. The base tag is useless for this topic.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fine. It was just an opinion.
 
H Austy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.




I have tried to use "server-relative" path as suggested by putting "/xyz" at the beginning of my links as my application is mapped to "/xyz" as the context path. HOWEVER , still to no avail.

<Host name="xyz.org.cn" appBase="/home/xyz/public_html">
<Alias>www.xyz.org.cn</Alias>
<Context path="/xyz" reloadable="true" docBase="/home/xyz/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the rest of the URL ok? What happens when you use the same URL in the address bar of the browser?
 
H Austy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The rest of the page also not ok.

Any idea on which other configuration file that I need to change other than server.xml to pake context path works? thanks
 
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic