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>
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With