Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide .jsp extension or change display name on URL

Tags:

java

jsp

servlets

How to hide .jsp extension or change display name on URL?

I'm using servlet-jsp communication. my web.xml code is

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>pub</servlet-name>
        <jsp-file>/publications.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>pub</servlet-name>
        <url-pattern>/publications</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>SciArchive</servlet-name>
        <servlet-class>controller.SciArchiveController</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SciArchive</servlet-name>
        <url-pattern>*.sci</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>home.jsp</welcome-file>
    </welcome-file-list>
</web-app>

I want to hide .jsp extenstion in URL ..../SciArchive/publications.jsp to ..../SciArchive/publications

like image 880
Hareesh Avatar asked Dec 02 '13 10:12

Hareesh


1 Answers

You already have publications.jsp mapped to a URL-pattern. Why are you not using this URL pattern to access the jsp. ?

<servlet>
  <servlet-name>pub</servlet-name>
  <jsp-file>/publications.jsp</jsp-file>
</servlet>
<servlet-mapping>
  <servlet-name>pub</servlet-name>
  <url-pattern>/publications</url-pattern> <!-- Use this URL -->
</servlet-mapping>

If you hit the URL http://somehost/SciArchive/publications , it will automatically call your jsp in the back-ground and the URL will remain the same (without the page name i.e without .jsp).

like image 177
Saif Asif Avatar answered Nov 01 '22 14:11

Saif Asif