Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map Html files with web.xml?

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.

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

Here's a normal login.html i want to map:

<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>
like image 960
chanchal karn Avatar asked Jul 11 '15 14:07

chanchal karn


People also ask

How do I create a map in web xml?

To map a URL to a servlet, you declare the servlet with the <servlet> element, then define a mapping from a URL path to a servlet declaration with the <servlet-mapping> element.

Where do you place web xml file?

This file is named web. xml , and resides in the app's WAR under the WEB-INF/ directory. web. xml is part of the servlet standard for web applications.

What is servlet mapping in web xml?

Servlet mapping specifies the web container of which java servlet should be invoked for a url given by client. It maps url patterns to servlets. When there is a request from a client, servlet container decides to which application it should forward to. Then context path of url is matched for mapping servlets.

What is URL pattern in web xml?

The url-pattern element of a servlet-mapping or a filter-mapping associates a filter or servlet with a set of URLs. When a request arrives, the container uses a simple procedure for matching the URL in the request with a url-pattern in the web. xml file.


1 Answers

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>

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

Change <url-pattern>/app/page</url-pattern> to any URL of your wish and URL with request will be redirected towards 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."

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

enter image description here

enter image description here

enter image description here

like image 122
hagrawal Avatar answered Sep 28 '22 22:09

hagrawal