隐藏.jsp扩展名或更改URL上的显示名称 [英] Hide .jsp extension or change display name on URL

查看:123
本文介绍了隐藏.jsp扩展名或更改URL上的显示名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏.jsp扩展名或更改URL上的显示名称?

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

我正在使用servlet-jsp通信。我的web.xml代码是

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>

我想隐藏URL中的.jsp扩展名 .... / SciArchive /publications.jsp
.... / SciArchive / publications

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

推荐答案

您已经将 publications.jsp 映射到URL模式。为什么不使用此URL模式来访问jsp。 ?

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>

如果您点击URL http:// somehost / SciArchive / publications ,它将自动在后台调用你的jsp,URL将保持不变(没有页面名称,即没有.jsp)。

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

这篇关于隐藏.jsp扩展名或更改URL上的显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆