3

In a website I have some links in a navbar like this

<li><a href="?page=pagename">PAGE</a></li>

and I load the linked page with JAVA in JSP page, then I submit data through a form by GET, after this my URL become

www.sitename.com/Servlet

then I'm not able to load the page by

?page=pagename 

because I have the Servlet name in the URL.

How I can hide or delete the servlet name?

bknopper
  • 1,193
  • 12
  • 28
sim186
  • 39
  • 3
  • 10

2 Answers2

0

Use a servlet-mapping in your web.xml:

<servlet-mapping>
  <servlet-name>Servlet</servlet-name>
  <url-pattern>/*</url-pattern> 
</servlet-mapping>
0

it's easier if all those JSPs are in a common path. E.g. /app/*.

<servlet>
    <servlet-name>app</servlet-name>
    <servlet-class>com.example.FriendlyURLServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>app</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

with

request.getRequestDispatcher("/WEB-INF" + request.getPathInfo() + ".jsp").forward(request, response);

This assumes the JSPs to be in /WEB-INF folder so that they cannot be requested directly. This will show /WEB-INF/search.jsp on http://example.com/app/search.

jmail
  • 5,944
  • 3
  • 21
  • 35