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>

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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.
one more thing how can I implement this if Im redirecting the page through my servlet? For example resp.sendRedirect("admin-home");
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.