1 native Portlet development This is the simplest and most essential development method. You can develop a Portlet directly based on the Interface defined in the Portlet specification. The advantage is that the bottom layer is relatively flexible, and the disadvantage is that everything should be done by yourself. It is just like using Servlet-based development without SpringMVC or Struts. This method is suitable for self-development of the Portlet framework. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 44 45 46 48 49 51 52 53 54 55 57 58 59 60 public class NativePortlet implements Portlet {private Logger logger = LoggerFactory. getLogger (NativePortlet. class); private PortletConfig config; @ Override public void init (PortletConfig portletConfig) throws PortletException {Logger.info ("initialize Portlet"); this. config = portletConfig ;}@ Override public void processAction (ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {logger.info ("processing Action"); logger.info ("received POST request, username: [{}] ", actionRequest. getParameter ("userName");} @ Override public void render (RenderRequest renderRequest, RenderResponse renderResponse) throws Portle TException, IOException {logger.info ("processing Render action"); WindowState state = renderRequest. getWindowState (); if (state. equals (WindowState. MINIMIZED) {return;} // doDispatch (); PortletMode mode = renderRequest. getPortletMode (); if (PortletMode. VIEW. equals (mode) {// doView (); String normalPage = config. getInitParameter ("ViewPage"); if (WindowState. NORMAL. equals (state) {this. include (renderRequest, RenderResponse, normalPage);} else {this. include (renderRequest, renderResponse, "") ;}} else if (PortletMode. EDIT. equals (mode) {// doEdit ();} else if (PortletMode. HELP. equals (mode) {// doHelp ();} else {throw new PortletException ("unknown portlet mode:" + mode) ;}}@ Override public void destroy () {logger.info ("Destroy Portlet");} private void include (RenderRequest request, RenderResponse r Esponse, String viewPage) throws PortletException, IOException {response. setContentType ("text/html"); PortletContext context = config. getPortletContext (); PortletRequestDispatcher requestDispatcher = context. getRequestDispatcher (viewPage); requestDispatcher. include (request, response) ;}}you can see that in the render () method, we have to handle rendering of different Portlet modes (View, Edit, Help, etc.) by ourselves, distribute as needed. Various details such as this need to be formulated and handled by ourselves. 2. The annotation Portlet development Portlet specification also provides the annotation method to develop the Portlet. In this way, you can easily develop A Portlet without relying on third-party frameworks such as SpringMVC Portlet, and you do not have to deal with implementation details at the very bottom layer. Let's look at an example. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41 42 public class AnnotatedPortlet extends GenericPortlet {private Logger logger = LoggerFactory. getLogger (AnnotatedPortlet. class);/*** enter the home page (View mode) * @ param request * @ param response * @ throws Exception */@ RenderMode (name = "view ") public void toIndexPage (RenderRequest request, Ren DerResponse response) throws Exception {getPortletContext (). getRequestDispatcher (getInitParameter ("ViewPage ")). include (request, response);}/*** save username * @ param request * @ param response */@ ProcessAction (name = "saveUsername") public void saveUsername (ActionRequest request, actionResponse response) {String userName = request. getParameter ("userName"); logger.info ("Save userName [{}]", userName );}/** * Save the email address * @ param request * @ param response */@ ProcessAction (name = "saveEmail") public void saveEmail (ActionRequest request, ActionResponse response) {String email = request. getParameter ("email"); logger.info ("save Email [{}]", email);} use the @ RenderMode annotation to define the implementation method of Portlet rendering in different modes. @ ProcessAction the annotation can directly send the request to the method marked with the annotation for Processing Based on the action name. We do not need to implement the Code for distributing the request according to the annotation. Appendix: Other code page code is as follows. Use the tags defined in the Portlet specification to generate ActionUrl. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 <% @ page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib uri =" http://java.sun.com/jstl/core_rt "prefix =" c "%> <% @ taglib uri =" http://java.sun.com/jstl/fmt "prefix =" fmt "%> <% @ taglib uri =" http://java.sun.com/ Jsp/jstl/functions "prefix =" fn "%> <% @ taglib uri =" http://java.sun.com/portlet_2_0 "prefix =" portlet "%> <portlet: defineObjects/>