JohnRambo
JohnRambo

Reputation: 518

Redirect to another jsp page after submitting a form

I have 2 jsp pages "/page1.jsp","/page2.jsp" and "file.java", after submitting a form from "/page1" i want to go to action method take some records from the database and go to the "/page2" with the records i have and list it. All is done but for some reason i cannot go to the "/page2" page it takes me somewhere else(another .jsp page).

I am using liferay and extending MVCPortlet class

Thanks in advance!!!.

public void AddCustomer(ActionRequest actionRequest, ActionResponse actionResponse) throws                  IOException, PortletException {

    ...

    pCustomer.setCustomerId(customerId);

    // set UI fields
    pCustomer.setName(cusName);
    pCustomer.setAddress(address);
    pCustomer.setComments(comments);
    try {
        PCustomerLocalServiceUtil.addPCustomer(pCustomer);
    } catch (com.liferay.portal.kernel.exception.SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ...
}

addCustomer.jsp:

<portlet:actionURL var="addCustomersAct" name="AddCustomer">
<portlet:param name="jspPage" value="/allCustomers.jsp"/>
</portlet:actionURL>  
<form method="post" action="<%= addCustomersAct %>">
 ...
</form>

allCustomers.jsp

<%for (PCustomer allCustomer : customers) { %>
<tr>
 ...//List of all customers
</tr>
<% } %>

On top of the addCustomers.jsp i have some more portlet parameters because I have a sidemenu and i need them for the render requests.

Upvotes: 1

Views: 24617

Answers (4)

chandan sharma
chandan sharma

Reputation: 111

In your addCustomer.jsp create one renderURL and provide this as hidden parameter as redirect url

...
    <portlet:renderURL var="redirectURL">
    <portlet:param name="jspPage" value="/html/yourhtmlpath/confirm.jsp"/>
    </portlet:renderURL>
...

and

<form>
    ...
        <aui:input name="redirectURL" type="hidden" value="${redirectURL}"></aui:input>
    ...
</form>

In Your processAction method after doing your task:

...
    actionResponse.sendRedirect(ParamUtil.getString(actionRequest, "redirectURL"));
...

Upvotes: 2

karthik
karthik

Reputation: 147

 In place of mul change the object according to your requirement whatever value you want which is redirected to jsp
        actionRequest.setAttribute("mul",mul);
        actionResponse.setRenderParameter("jspPage", "/jsp/b.jsp");
In jsp:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<h6>Mul</h6>
<%= renderRequest.getAttribute("mul") %>

Upvotes: 0

Rohan
Rohan

Reputation: 3078

After catch block you can add following code statement.

actionResponse.sendRedirect("page2.jsp");

Upvotes: 1

M Sach
M Sach

Reputation: 34424

Well would like to see more code snippet.Here it is to forward the request to another jsp

    String destination = "page2.jsp"; // using relative path here
        RequestDispatcher rd = getServletContext().getRequestDispatcher(destination);
        rd.forward(request, response);

make sure you are using right path for destination jsp

Upvotes: 0

Related Questions