Skip to content

Commit 329658f

Browse files
Web.xml demo
1 parent b6c453d commit 329658f

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itbulls.learnit.onlinestore.web.servlets;
2+
3+
import jakarta.servlet.http.HttpServlet;
4+
import java.io.IOException;
5+
import jakarta.servlet.ServletException;
6+
import jakarta.servlet.annotation.WebServlet;
7+
import jakarta.servlet.http.HttpServletRequest;
8+
import jakarta.servlet.http.HttpServletResponse;
9+
10+
@WebServlet("/context-param")
11+
public class ContextParamValueServlet extends HttpServlet {
12+
13+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
14+
response.getWriter().println("Context param: " + getServletContext().getInitParameter("contextParam"));
15+
}
16+
17+
18+
}

Diff for: online-store.web/src/main/webapp/WEB-INF/web.xml

+59-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,61 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
3-
<display-name>onlinestore</display-name>
4-
<welcome-file-list>
5-
<welcome-file>index.html</welcome-file>
6-
<welcome-file>index.htm</welcome-file>
7-
<welcome-file>index.jsp</welcome-file>
8-
<welcome-file>default.html</welcome-file>
9-
<welcome-file>default.htm</welcome-file>
10-
<welcome-file>default.jsp</welcome-file>
11-
</welcome-file-list>
12-
13-
14-
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
5+
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
6+
id="WebApp_ID" version="4.0">
7+
<display-name>onlinestore</display-name>
8+
<welcome-file-list>
9+
<welcome-file>index.html</welcome-file>
10+
<welcome-file>index.htm</welcome-file>
11+
<welcome-file>index.jsp</welcome-file>
12+
<welcome-file>default.html</welcome-file>
13+
<welcome-file>default.htm</welcome-file>
14+
<welcome-file>default.jsp</welcome-file>
15+
</welcome-file-list>
16+
17+
<servlet>
18+
<servlet-name>helloWorldServlet</servlet-name>
19+
<servlet-class>com.itbulls.learnit.onlinestore.web.servlets.HelloWorldServlet</servlet-class>
20+
<init-param>
21+
<param-name>greetings</param-name>
22+
<param-value>Hello World</param-value>
23+
</init-param>
24+
<load-on-startup>0</load-on-startup>
25+
</servlet>
26+
27+
<servlet-mapping>
28+
<servlet-name>helloWorldServlet</servlet-name>
29+
<url-pattern>/hello-world</url-pattern>
30+
</servlet-mapping>
31+
32+
<context-param>
33+
<param-name>contextParam</param-name>
34+
<param-value>Context Param Value</param-value>
35+
</context-param>
36+
37+
<security-constraint>
38+
<web-resource-collection>
39+
<web-resource-name>test-auth</web-resource-name>
40+
<url-pattern>/test-auth</url-pattern>
41+
<http-method>GET</http-method>
42+
</web-resource-collection>
43+
<auth-constraint>
44+
<role-name>client</role-name>
45+
</auth-constraint>
46+
47+
<user-data-constraint>
48+
<!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
49+
<transport-guarantee>NONE</transport-guarantee>
50+
</user-data-constraint>
51+
</security-constraint>
52+
53+
<login-config>
54+
<auth-method>BASIC</auth-method>
55+
</login-config>
56+
57+
<session-config>
58+
<session-timeout>15</session-timeout>
59+
</session-config>
60+
1561
</web-app>

0 commit comments

Comments
 (0)