Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

java - Hide .jsp extension or change display name on URL

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...