0

Here's my scenario...My homepage link is

local/proj/admin-home

when I browse in another link like

local/proj/registration/organization-registry

but on that page when I hover my mouse in another link the link gives me

local/proj/registration/list

But this link must be

local/proj/list

So I noticed that when I browse to the link local/proj/registration/organization-registry all of the links in that page also starts with local/proj/registration/ but it must be /local/proj/ only...

here's my xml file

<servlet>
<servlet-name>admin-home</servlet-name>
<servlet-class>web.HomeServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>admin-home</servlet-name>
<url-pattern>/admin-home</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>list</servlet-name>
<servlet-class>ViewRegisteredServlet.RegisteredOrganizationServlet</servlet-class>
</servlet>

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

<servlet>
<servlet-name>organization-registry</servlet-name>
<servlet-class>web_registration.OrganizationServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>organization-registry</servlet-name>
<url-pattern>/registration/organization-registry</url-pattern>
</servlet-mapping>
PeterJohn
  • 589
  • 3
  • 8
  • 15

1 Answers1

2

You was apparently using a relative link. A relative link is a link which does not start with the scheme (e.g. http://), nor with a forward slash / which would take you to the domain root.

<a href="list">list</a>

Such a link is relative to the current URL (as you see in browser's address bar). So it's basically pointing to the resource in the same folder.

You actually need to go one folder up:

<a href="../list">list</a>

Or, better, make it domain-relative, so that you don't need to mess with links whenever you move resources around.

<a href="${pageContext.request.contextPath}/list">list</a>

This all has nothing to do with your servlet mappings. This is just a basic web development concept.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Im using one page for all the menus in all of the page. So I just need to put ${pageContext.request.contextPath}/ in all of my links? – PeterJohn Feb 03 '13 at 01:21
  • Technically, yes the most robust way is to prepend all your webapp-specific links with the context path. See also the "see also" link for tips how to make this less bloated. – BalusC Feb 03 '13 at 01:23
  • one more thing how can I implement this if Im redirecting the page through my servlet? For example resp.sendRedirect("admin-home"); – PeterJohn Feb 03 '13 at 01:33
  • Just use `response.sendRedirect(request.getContextPath() + "/admin-home")`. Note that many if not all Java EE based MVC frameworks take this transparently into account, e.g. JSF. – BalusC Feb 03 '13 at 01:40