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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With