Goal:
To call a servlet from portlet deployed in liferay 6.
Solution:
Step 1: Create a servlet
public class myServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException {
System.out.println ("inside servlet");
response.sendRedirect(portal_url); //url of portal page
}
}
myServlet.java is a simple servlet class in which service() method serves the purpose of redirecting the control back to portal page. portal_url is the actual absolute URL where the servlet should redirect after processing.
Step 2: Configuring web descriptor
Go to portlet web.xml and make an entry like below:
<servlet>
<servlet-name>myAction</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.rdg.portlet.myServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>myAction</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-name>myAction</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.rdg.portlet.myServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>myAction</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
In the above web descriptor com.liferay.portal.kernel.servlet.PortalDelegateServlet serves to redirect any request coming to "http://localhost:8080/myAction" to service() method of com.rdg.portlet.myServlet and will redirect back to the liferay portal url.
Step 3: Creating portlet action class to redirect to the servlet
public class myPortletAction extends MVCPortlet {
public void redirectMe(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
ActionResponse actionResponse) throws IOException, PortletException {
actionResponse.sendRedirect("http://localhost:8080/myAction");
}
}
So when a form is submitted to the action and control is sent to redirectMe() method, it redirects the request to "http://localhost:8080/myAction" for further processing.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteMy gratitude for the wonderful words. We want you to continue this for us.
ReplyDeleteGraphic Designing in Coimbatore https://weassistplus.in/
A Super Specialized place for Web Designing, Logo Designing, Brochure, Stationary items, google ads, Social Media Analyst, SEO maintenance for your company.
I am Appreciating & Thanking you for a wonderful article. Thanks a lot.
ReplyDeletehttps://araseefoods.com/
Good tasty and healthy food products in Erode and Coimbatore
Food product manufacturers in Erode and Coimbatore
Food product Suppliers in Erode and Coimbatore
Cheap and Best Food products in Erode and Coimbatore
Bajji mix flour product Manufacturers in Erode and Coimbatore
Corn flour product Manufacturers in Erode and Coimbatore
Flattened Rice product Manufacturers in Erode and Coimbatore
Gram Flour product Manufacturers in Erode and Coimbatore
Karumbu sakkarai product Manufacturers in Erode and Coimbatore
Maida Flour product Manufacturers in Erode and Coimbatore
Pottu kadalai Flour product Manufacturers in Erode and Coimbatore
Ragi Flour product Manufacturers in Erode and Coimbatore
Rava Manufacturers in Erode and Coimbatore
Semiya Manufacturers in Erode and Coimbatore
Atta Manufacturers in Erode and Coimbatore
Wheat Rava Manufacturers in Erode and Coimbatore
We overwhelm this article. This is a big information for us.
ReplyDeletehttps://alpharealtors.in/
Leading Real Estate Company in Coimbatore
Affordable and Luxury Property Sellers in Coimbatore
Value added property Sellers in Coimbatore
Best Residential Property Sellers in Coimbatore
Best Industrial Property Sellers in Company in Coimbatore