Following is an example.
jspconfig.html
[html]
<html>
<body>
<h2><a href="./welcome">click here</a></h2>
</body>
</html>
[/html]
Here just created the button
Click here, the URL name should be match with
web.xml file URL.
web.xml
[xml]
<web-app>
<servlet>
<servlet-name>Config</servlet-name>
<jsp-file>/configObject.jsp</jsp-file>
<init-param>
<param-name>user_name</param-name>
<param-value>SPlessons</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Config</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
[/xml]
Here make sure that servlet name should be same that is
Config, URL should be match with HTML form, parametes are passing from the
web.xml file by using the tag
.
configObject.jsp
[java]
<h2>
<% String userName = config.getInitParameter("user_name");
out.println("your name get from web.xml:"+userName); %>
</h2>
[/java]
Here name will be retrieved from the
web.xml page that is
SPlessons and that will be printed using out.println.
Output
Output will be as follows, where click on the
click here button that was created in main page
jspconfig.html .
After clicking on the button output will be as follows with the name that was mentioned in the
web.xml .