Link to home
Start Free TrialLog in
Avatar of atwoodj
atwoodj

asked on

servlet mapping, JSP includes and site root relative links

I am very new to JSP and includes so please pardon my ignorance. I'm sure this is a simple problem to fix, but I've searched and I'm stumped. I am developing the site locally and then will deploy it on the company server. For this reason I want the code to work when it's uploaded to the server.

I want to have a navigation menu & top banner that I include on almost all pages of my app. The app is locally deployed in my webapps directory and can be accessed using http://localhost:8080/simceo/index.jsp.

I have use the following code to include the file:                   <%@ include file="/inc/topbanner.jsp" %>

The topbanner.jsp page has the main navigation links for the site. Since this file will be included in files in other directories of the site (such as the /student/index.jsp and /admin/index.jsp page, I thought it best to use links relative to the site root so that no matter which directory the included topbanner.jsp file was in, the links would work.

The problem is that since the application is locally accessed at http://localhost:8080/simceo/ all of the links that use the site root relative format go back to the //localhost:8080 directory and cannot be found as this is the default for the Tomcat that was created with the installation.

Is there some configuration that I can set to make the links go to the correct path? Is this a servlet-mapping setting or something? I have read some about this, but I don't know how to set it.

My web.xml file defines the application as follows:

      <servlet-mapping>
            <servlet-name>simceo</servlet-name>
            <url-pattern>/simceo</url-pattern>
      </servlet-mapping>

I'm using Tomcat 5.5.23. I'm not sure what other information you need. Please let me know. Thanks
ASKER CERTIFIED SOLUTION
Avatar of evnafets
evnafets

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atwoodj
atwoodj

ASKER

Thanks for the comments -- like I said I'm very new to all of this! We will actually be using struts. I have some programmers that will be doing the struts coding at a later date. Can you give me an example of how to code the links using the struts <html:link> tag?

Thanks
Avatar of atwoodj

ASKER

One other question...

The topbanner.jsp page also has images in it. Can I use a struts tag to load these images as well? The paths to these images will change depending on the page which includes the topbanner.jsp page.

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you say the paths to these images will change, you can still use <img src='<%= request.getContextPath () %>/folder/with/images/myfile.gif'/> to link to an image no matter what page your in...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried <html:img page="<%= request.getParameter("imageURL") %>" /> and I'm pretty sure that will not compile in a JSP.  I don't think you can embed JSP code within a JSTL tag, at least not with my current configuration tools and compilers.

You'd probably have to use <img src='<%= request.getParameter("imageURL")  %>/folder/with/images/myfile.gif'/> instead.
Well you know what I mean:  <img src='<%= request.getParameter("imageURL")  %>'/>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atwoodj

ASKER

Thanks to both of you for your comments. They have all been helpful.

I had not planned on having the images change as you were discussing -- but I might consider it now that I have seen how it might work.

For the time being I have gone with the request.getContextPath() solution as we have not completed our struts configuration.