2012-10-12 27 views
0

我正在開發一個liferay portlet。這不是我第一次這樣做,但得到一個簡單的錯誤,我不明白爲什麼我得到這個錯誤。當我點擊提交按鈕,我得到這個錯誤「找不到請求的資源」當在Liferay portlet中提交表單時

找不到請求的資源。 「http:// localhost:8081/addProduct」

這不僅僅是幾小時我正在努力解決它,而且我知道我犯了一個愚蠢的錯誤。任何機構能幫我解決這個問題嗎?提前感謝任何幫助。這裏是我的JSP代碼:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> 
<%@ page import="javax.portlet.PortletURL" %> 

<portlet:defineObjects /> 

This is the <b>ServiceBuilderTest</b> portlet. 
<portlet:actionURL var="addProduct" name="addProductAction"/> 

<aui:form method="post" action="addProduct"> 
    <aui:fieldset> 
     <aui:input name="productName" label="Product Name"></aui:input> 
     <aui:input name="userID" label="User ID"></aui:input> 
     <aui:input name="companyID" label="company ID"></aui:input> 
     <aui:input name="groupID" label="Group ID"></aui:input>  
     <aui:input name="serialNumber" label="Serial Number"></aui:input> 
     <aui:button type="submit" value="Submit"></aui:button> 
    </aui:fieldset> 
</aui:form> 

這是我的portlet類代碼:

public class ServiceBuilderPortlet extends MVCPortlet{ 
    public void addProductAction(ActionRequest actionReauest, ActionResponse   actionResponse) throws SystemException, PortalException 
    {    
     String productName = actionReauest.getParameter("productName"); 
     String userID = actionReauest.getParameter("userID"); 
     String companyID = actionReauest.getParameter("companyID"); 
     String groupID = actionReauest.getParameter("groupID"); 
     String serialNumber = actionReauest.getParameter("serialNumber"); 
     PRProduct product =  PRProductLocalServiceUtil.addProduct(Long.parseLong(companyID), Long.parseLong(groupID),  productName, 
       serialNumber, Long.parseLong(userID));     
    } 
} 
+0

請張貼異常,以及你的mvcPortlet代碼 –

+0

'公共無效addProductAction(的ActionRequest actionReauest,ActionResponse的ActionResponse的)拋出SystemException的,PortalException {}'不應該的方法的名稱是' addProduct'? –

+0

編號 name屬性是方法名稱。 – Beginner

回答

0

使其

<portlet:actionURL var="addProduct" name="addProductAction"/> 
<aui:form method="post" action="<%=addProduct%>"> 
    ... 

實際上,我認爲這是對不上名字的最佳實踐動作「addProductAction」,但只是「addProduct」,所以更改將如此(包括一行java,其餘看起來不錯(視覺上,未嘗試/測試):

<portlet:actionURL var="addProduct" name="addProduct"/> 
<aui:form method="post" action="<%=addProduct%>"> 
    .... 

public class ServiceBuilderPortlet extends MVCPortlet{ 
    public void addProduct(ActionRequest request, ActionResponse response) throws SystemException, PortalException { 
     // ... 
    } 
} 
+0

你是對的Olaf。感謝您的回答。順便說一下,您有使用Service Builder的經驗嗎?我遇到問題。 – Beginner

+0

好吧,繼續問下一個問題,我們會看到(但我不知道我是否可以在第二天回答 - 本週這裏很忙) –

+0

好的。我會發布我的問題。提前致謝。 – Beginner