Liferay portal simple demo

Source: Internet
Author: User

Create a simple web project in myeclipse:

 

(1) create a class under SRC and inherit from genericportlet. The Code is as follows:

Package COM. portlet; </P> <p> Import Java. io. ioexception; </P> <p> Import javax. portlet. actionrequest; <br/> Import javax. portlet. actionresponse; <br/> Import javax. portlet. genericportlet; <br/> Import javax. portlet. portletexception; <br/> Import javax. portlet. renderrequest; <br/> Import javax. portlet. renderresponse; </P> <p> public class mytableportlet extends genericportlet {</P> <p> @ override <br/> protected voi D doview (renderrequest request, renderresponse response) <br/> throws portletexception, ioexception {<br/> string name = request. getparameter ("name"); </P> <p> If (name = NULL | "". equals (name) {<br/> This. getportletcontext (). getrequestdispatcher ("/table. JSP "). include (request, response); </P> <p >}< br/> else {<br/> This. getportletcontext (). getrequestdispatcher ("/display. JSP? Username = "+ name ). include (request, response); <br/>}</P> <p> @ override <br/> protected void doedit (renderrequest request, renderresponse response) <br/> throws portletexception, ioexception {<br/> This. getportletcontext (). getrequestdispatcher ("/table. JSP "). include (request, response); <br/>}</P> <p> @ override <br/> Public void processaction (actionrequest arg0, actionresponse arg1) <br/> throws portletexception, ioexception {<br/> system. out. println ("processaction method"); <br/>}</P> <p> @ override <br/> Public void render (renderrequest request, renderresponse response) <br/> throws portletexception, ioexception {<br/> This. doview (request, response); <br/>}< br/>}

 

 

(2) Create Table. jsp and the display. jsp codes are as follows:

1. Table. jsp:

<% @ Page import = "javax. portlet. portleturl "%> <br/> <% @ page import =" javax. portlet. renderresponse "%> <br/> <% @ taglib uri =" http://java.sun.com/portlet "prefix =" Portlet "%> <br/> <% @ page Language =" Java "contenttype =" text/html; charset = GBK "%> <br/> <Portlet: defineobjects/> <br/> <% <br/> // an error is reported, but no object is found, but don't worry about it (like this) <br/> portleturl Pu = renderresponse. createrenderurl (); <br/> Pu. setparameter ("AAA", "BBB"); <br/> // portleturl Pu = (renderresponse) response ). createactionurl (); <br/>%> <br/> <form method = "Post" Action = "<% = Pu. tostring () %> "> <br/> <Table border =" 1 "> <br/> <tr> <br/> <TD> Username: </TD> <br/> <TD> <input type = "text" name = "name"/> </TD> <br/> </tr> <br/> <tr align = "center"> <br/> <TD colspan = "2"> <input type = "Submit"/> </TD> <br/> </ tr> <br/> </table> <br/> </form>

 

2. display. jsp:

<% @ Taglib uri = "http://java.sun.com/portlet" prefix = "Portlet" %> <br/> <% @ page Language = "Java" contenttype = "text/html; charset = GBK "%> </P> <p> <Portlet: defineobjects/> <br/> <% <br/> string name = request. getparameter ("username"); <br/>%> <br/> <p> welcome, <% = Name %> </P>

 

(3) download the liferay-portal-tomcat-4.2.1.zip and decompress it to the F:/liferay/tomcat directory (this is what I did on my machine)

 

(4) To F:/liferay/tomcat/webapps/root/WEB-INF directory to configure three XML files

1. Add in the portlet-ext.xml file:

<Portlet> <br/> <Portlet-Name> mytableportlet </Portlet-Name> <br/> <display-Name> mytableportlet </display-Name> <br/> <portlet-class> COM. portlet. mytableportlet </Portlet-class> <br/> <expiration-Cache> 0 </expiration-Cache> <br/> <supports> <br/> <mime-type> text /html </mime-type> <br/> </supports> <br/> <mime-type> text/html </mime-type> <br/> <Portlet-mode> edit </Portlet-mode> <br/> </supports> <br/> <Portlet-Info> <br/> <title> mytableportlet </title> <br/> <short-title> mytableportlet </short-title> <br/> <keywords> mytableportlet </keywords> <br/> </ portlet-Info> <br/> <Portlet-preferences> <br/> <preference> <br/> <Name> Portlet-title </Name> <br/> <Value> </value> <br/> </preference> <br/> <Name> show-Portlet-borders </Name> <br/> <value> true </value> <br/> </preference> <br/> </Portlet-preferences> <br/> <security-role-ref> <br/> <role-Name> guest </role-Name> <br/> </security-role-ref> <br/> <security-role-ref> <br/> <role-Name> power user </role-Name> <br/> </security-role-ref> <br/> <security-role-ref> <br/> <role-Name> User </role-Name> <br/> </security-role-ref> <br/> </Portlet>

 

2. Add in the liferay-portlet-ext.xml file:

<Portlet> <br/> <Portlet-Name> mytableportlet </Portlet-Name> <br/> <use-default-template> true </use-default-template> <br/> <instanceable> true </instanceable> <br/> </Portlet>

 

3. Add:

<Category name = "category. Test"> <br/> <Portlet id = "mytableportlet"/> <br/> </Category>

 

 

(5) copy the. Class file to the corresponding F:/liferay/tomcat/webapps/root/WEB-INF/classes directory

 

 

(6) Start the startup. Bat service under F:/liferay/tomcat/bin, and the program can run.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.