chanchal karn
chanchal karn

Reputation: 567

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>

Upvotes: 15

Views: 34287

Answers (1)

hagrawal7777
hagrawal7777

Reputation: 14668

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

Upvotes: 29

Related Questions