• 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

Linking to HTML

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am setting up a web service which will utilize JSP to create web content.

I have successfully installed and am utilizing the NetBeans IDE 4.1 with JSP- I can write jsp code and it is working properly.

However, when I link to an html page on the same site, the link does not work.

For example, my link is

<a href="/Test.html">Test</a><br>

My Test.html file is located in

Web Pages
WEB-INF
Test.html


When I run the application, it comes up with

type Status report

message /Test.html

description The requested resource (/Test.html) is not available.


Any ideas? Is there something I am missing?

Thank you
 
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
Is your HTML page under the WEB-INF directory?
It's hard to tell from the way you've posted it.
If so, you'll need to move out from under there in order for the browser to be able to see it.

Also if you use a relative link to a page and preceed it with a forward slash, the browser will treat that link as being relative to the domain (the contextPath will be excluded).



The best way to create relative links is to read the contextPath from the request.

${pageContext.request.contextPath}/myPage.html
 
Tom Tolman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is under the WEB-INF folder structure. I was assuming I would place my html files in the same folder structures as the jsp files, but I guess this was an incorrect assumption.

By placing the file at the root (above WEB-INF) I have been able to get the url to work, this is great. (I utilized your context dependency:


However now I am curious what the correct layout for the web pages are. That is to say, if I wish to have jsp and html files interleaved, what would be the correct layout to perform this?

For example, I am going have some of my web pages with pure content that is predetermined (html) and some that is dynamically created (with jsp). Should I have completely separate, but parallel files?

I am going to have sections of material (in html), broken up with quizzes on this material (created from jsp). So would I create something like:



For every single section? I had been planning on putting the html and the jsp in the same folder for the same content.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They should be under the /section1/ folder as well.
[ September 20, 2006: Message edited by: Matthew Egbers ]
 
Sheriff
Posts: 67747
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

Originally posted by Matthew Egbers:
They should be under the /section1/ folder as well.



"should" is way too strong a word here. "could" would be more appropriate.

JSPs customarily get placed under WEB-INF in a Model 2 web application to prevent them from being directly addressed outside the context of their controllers.

As you have seen, placing a resource (be it HTML or JSP) under WEB-INF prevents direct addressing via URL.

Moving the JSPs out of WEB-INF just for some artificial reason such as tidyness would be a mistake as you are losing the benefit of hiding the JSPs just for the sake of a development artifact.

If you feel you must keep the files in the same folder, you could move the JSPs out of WEB-INF, but be aware of the remifications. If you wanted to move the HTML files under WEB-INF, you could write a relay servlet that could find and serve the HTML files.

Personally, I'd keep the JSPs under WEB-INF, and the HTML files outside of WEB-INF in a folder structure that made their correspondence clear.
[ September 20, 2006: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic