Java 如何使用 web.xml 映射 Html 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31358286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to map Html files with web.xml?
提问by chanchal karn
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.
好的,我试图到处找到这个答案。我想在这里做的是用一个 url 映射一个 html 文件..?是的,我可以使用 app/page.html 访问 html 文件。但我想将它映射到不同的网址。
I know how to map servlet classes and jsp files , but i dont know how to map html files.
我知道如何映射 servlet 类和 jsp 文件,但我不知道如何映射 html 文件。
Here's a normal login.html
i want to map:
这是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>
回答by hagrawal
Here you go. URL as /app/page
will show your page.html
干得好。URL as/app/page
将显示您的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>
Please notethat page.html
should be directly inside your context root or in other words directly in your *.war.
请注意,它page.html
应该直接在您的上下文根中,或者直接在您的 *.war 中。
Change <url-pattern>/app/page</url-pattern>
to any URL of your wish and URL with request will be redirected towards page.html
更改<url-pattern>/app/page</url-pattern>
为您希望的任何 URL 和带有请求的 URL 将被重定向到page.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."
需要注意的关键是——“在jsp-file
元素中,你可以指定一个JSP或HTML,其内容可以解析为HTML形式。”
And that is the same reason that in <welcome-file>
element you can specify either a HTML or JSP file.
这与在<welcome-file>
element 中可以指定 HTML 或 JSP 文件的原因相同。