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</serv let-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
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</serv
<url-pattern>/simceo</url-
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you say the paths to these images will change, you can still use <img src='<%= request.getContextPath () %>/folder/with/images/myfi le.gif'/> to link to an image no matter what page your in...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I tried <html:img page="<%= request.getParameter("imag eURL") %>" /> 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("imag eURL") %>/folder/with/images/myfi le.gif'/> instead.
You'd probably have to use <img src='<%= request.getParameter("imag
Well you know what I mean: <img src='<%= request.getParameter("imag eURL") %>'/>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Thanks