简体   繁体   中英

How to call Generic Portlet methods from servlet?

I have created a portlet and able all my business logic is performing in a servlet. I need to get the liferay login user details in the servlet. SO I have created a class which will extend the GenericPortlet . Now My question is how can I call that class I need to execute the GenericPorlet unimplemented method. My code is as follows,

public class ActionProcess extends GenericPortlet {

    public void init() throws PortletException{
        super.init();
    }

    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
             User user = (User) request.getAttribute(WebKeys.USER);
             ThemeDisplay td  =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
             User urs = td.getUser();
             System.out.println("doView "+ urs);
             System.out.println("doView "+ user);
    }
}

Now I need to call the doView() and return the values to servlet. How can I do that my servlet code is.

@WebServlet("/demoClass")
public class demoClass extends HttpServlet {
        private static final long serialVersionUID = 1L;

    public demoClass() {
        super();
        // TODO Auto-generated constructor stub
    }
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                 doPost(request, response); // 
        }
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//Here I am performing the business logic....
//How do I call the ActionProcess class here, I need to get the User name which is return by diView() method
}
}

Any suggestions?

You can't, and my answer is very similar to my answer to your very similar question .

It's the framework's (portal's) business to call the lifecycle methods of a portlet. Not yours.

You need to rethink your problem and come up with a different architecture. Or give us your problem to suggest a different solution than the one that you're currently pursuing.

Differing from that answer, I'm assuming that in this case you're within the very same same web application (portlet and servlet are deployed in the same webapp). However, just like in that other question , a portlet's request is routed through the portal while the servlet's request is not. You'll not have the data available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM