Blogs

Blogs

Servlet Configuration in Liferay DXP portlet

Description: For Servlet configuration in Liferay DXP portlet,  we will need to make necessary changes to the configuration files. Start with making a plugin custom portlet and add a servlet to this portlet, then do following configurations
 
Step 1:  Make sure bnd file has web context path (bnd.bnd)
Bundle-Name: hello-world-service
Bundle-SymbolicName: HelloWorldService
Bundle-Version: 1.0.0
Web-ContextPath: /myContext
 
Step 2:  Make sure gradle file has servlet dependency added. (build.gradle)
dependencies {
......
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
....
}
 
Step 3:  web.xml  should have servlet mapping. You may have to create web.xml if it does not exist at the following path:  \hello-world-service\src\main\resources\WEB-INF
 
<servlet-mapping>
<servlet-name>helloWorldServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
 
 
URL to Access:  http://localhost:8080/o/myContext/MyServlet