ActionProces.java
package com.jsrtutorial.secondexample;
import java.io.*;
import javax.portlet.*;
public class ActionProcess extends GenericPortlet {
public static final String JSP_FOLDER = "/_ActionProcessExample/jsp/";
public static final String VIEW_JSP = "ActionProcessView";
public void init() throws PortletException{
super.init();
}
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
// Invoke the JSP to render
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
}
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
String myname=request.getParameter("myname");
System.out.println("Name is :"+myname);
}
private static String getJspFilePath(RenderRequest request, String jspFile) {
String markup = request.getProperty("wps.markup");
if( markup == null )
markup = getMarkup(request.getResponseContentType());
return JSP_FOLDER + markup + "/" + jspFile + "." + getJspExtension(markup);
}
private static String getMarkup(String contentType) {
if( "text/vnd.wap.wml".equals(contentType) )
return "wml";
else
return "html";
}
private static String getJspExtension(String markupName) {
return "jsp";
}
}
ActionProcessView.jsp
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.jsrtutorial.secondexample.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
<FORM method="POST" action="<portlet:actionURL/>">
<LABEL for="name">Enter Name:</LABEL><BR>
<INPUT name="myname" type="text" value="${param.myname}"/>
<INPUT name="submit" type="submit" value="Submit"/>
</FORM>