如何使用web.xml映射HTML文件? [英] How to map Html files with web.xml?

查看:441
本文介绍了如何使用web.xml映射HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我试图在所有地方找到这个答案.我在这里想要做的是用url映射一个html文件吗? 是的,我可以使用app/page.html访问html文件.但我想将其映射到其他网址.

Ok i tried to find this answer everywhere. What im trying to do here is mapping an html file with a url..? Yes i can access the html file by using app/page.html. But i want to map it to a different url.

我知道如何映射servlet类和jsp文件,但是我不知道如何映射html文件.

I know how to map servlet classes and jsp files , but i dont know how to map html files.

这是我要映射的普通login.html:

<body>
    <form name="loginForm" method="post" action="/Logging..in">
        Username:<input type="text" name="user" />
        <br/>
        PassWord:<input type="password" name="pass">
        <br/>
        <input type="submit" value="Sign Up!">
    </form>
</body>

推荐答案

在这里. URL为/app/page将显示您的page.html

Here you go. URL as /app/page will show your page.html

<servlet>
    <servlet-name>page</servlet-name>
    <jsp-file>/page.html</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>page</servlet-name>
    <url-pattern>/app/page</url-pattern>
</servlet-mapping>

请注意page.html应该直接位于上下文根目录之内,或者直接位于* .war中.

Please note that page.html should be directly inside your context root or in other words directly in your *.war.

<url-pattern>/app/page</url-pattern>更改为您希望的任何URL,带有请求的URL将被重定向到page.html

Change <url-pattern>/app/page</url-pattern> to any URL of your wish and URL with request will be redirected towards page.html

要注意的关键是-"jsp-file元素中,您可以指定JSP或HTML,其内容可以解析为HTML形式."

Key thing to note is that - "In jsp-file element, you can specify a JSP or HTML, whose content can be resolved to HTML form."

这与在<welcome-file>元素中可以指定HTML或JSP文件的原因相同.

And that is the same reason that in <welcome-file> element you can specify either a HTML or JSP file.

这篇关于如何使用web.xml映射HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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