Seeya K
Seeya K

Reputation: 1331

Pass parameter from java class to jsp using ActionRequest Actionresponse

I have a function say :

 public void display(ActionRequest areq, ActionResponse ares) throws Exception,PortletException,IOException {

 String name= areq.getParameter("name");
 String add= areq.getParameter("add");
 String phone= areq.getParameter("phone");
}

I have a jsp say disp.jsp which passes the user input to the above function display. Now I after doing some processing on the above data in display() function, I want to display the results on a jsp page say new.jsp. How should I go ahead with it? I tried something like:

areq.setAttribute("name",name);
areq.getRequestDispatcher("new.jsp").forward(areq, aresp); but it shows an error that getRequestDispatcher is not defined for actionrequest and actionresponse.

I am using liferay framework

Upvotes: 0

Views: 8770

Answers (1)

yannicuLar
yannicuLar

Reputation: 3133

In your action you can set attributes and set the redirect page like that:

public void display(ActionRequest aReq, ActionResponse aResp){


    aReq.setAttribute("name",name);

    aResp.setRenderParameter("jspPage", "/new.jsp");
}

I Usually prefer setting attributes instead of Parameters, because it allows to pass non Sting variables. Then, in the jsp you can get the attributes

<%
String name = (String)renderRequest.getAttribute("name");   
%>

Just remember to include this, to have access to renderRequest object

<portlet:defineObjects />

Upvotes: 2

Related Questions