Java Liferay<;portlet:actionURL>;
在我的jsp中,我有以下代码:Java Liferay<;portlet:actionURL>;,java,jsp,tags,liferay,liferay-6,Java,Jsp,Tags,Liferay,Liferay 6,在我的jsp中,我有以下代码: <portlet:actionURL name="addDetails" var="addDetailsURL" /> <aui:form name="addDetails" action="<%=addDetailsURL.toString() %>" method="post" > <aui:input type="text" label="name:" name="name" value="" /&g
<portlet:actionURL name="addDetails" var="addDetailsURL" />
<aui:form name="addDetails" action="<%=addDetailsURL.toString() %>" method="post" >
<aui:input type="text" label="name:" name="name" value="" />
<aui:input type="text" label="surname:" name="surname" value="" />
<aui:input type="text" label="age:" name="age" value="" />
<aui:button type="submit" value="addDetails" />
</aui:form>
我正在使用liferay。我想提交将在java类中处理的数据。
我的java类几乎没有函数。我应该如何在上面的jsp中指定它应该在提交表单后访问java中的特定函数?如果您只想处理一个操作: Portlet
@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
{
// TODO Auto-generated method stub
super.processAction(actionRequest, actionResponse);
}
JSP
JSP
JSP
如果您的portlet继承了
MVCPortlet
,只需创建一个与actionURL具有相同“名称”的公共方法,该方法采用ActionRequest
和ActionResponse
参数:
public void addDetails(ActionRequest req, ActionResponse rsp) {
// ...
}
仅为了记录,您还可以使用注释。例如,您有以下jsp:
您的MVCPortlet
中的这个Java方法:
@ProcessAction(name=“myAction”)
公共无效方法(ActionRequest ActionRequest、ActionResponse ActionResponse){
// ...
}
如果您使用的不是MVCPortlet,而是GenericPortlet之类的东西,请向actionURL添加一个参数,如下所示:
<portlet:actionURL name="addDetails" var="addDetailsURL" >
<portlet:param name="method" value="addDetails"/>
</portlet:actionURL>
如果您的java类正在扩展MVCPortlet,那么只有方法名称应该与actionURL名称匹配,即addDetails。如果类正在扩展GenericPortlet,则必须在方法的顶部为其指定注释,如@ProcessAction(name=“addDetails”)。在这种情况下,方法的名称可以不同。将其粘贴到控制器类中
public void addDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
//this method will be called on submitting the form
System.out.println("addDetails");
}
或者你可以把它当作
@ProcessAction(name="addDetails")
public void myaddDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
//this method will be called on submitting the form
System.out.println("addDetails");
}
如果java类中有很多函数呢?那么它怎么知道它应该去哪个函数呢?珀普:那么在我上面的actionURL中:name是addDetails,那么我的函数名应该是addDetails,对吗?你也可以使用@ProcessAction注释。
<portlet:resourceURL var="resourceUrl" />
<input id="resourceURL" type="hidden" value="${resourceUrl}" />
$.post($('#resourceURL').val(),{
action : 'myAction'
}).done(function(result){
alert('Action completed successfully!')
});
public void addDetails(ActionRequest req, ActionResponse rsp) {
// ...
}
<portlet:actionURL name="addDetails" var="addDetailsURL" >
<portlet:param name="method" value="addDetails"/>
</portlet:actionURL>
public void processAction(ActionRequest aReq, ActionResponse aResp) throws IOException,
PortletException {
final String method = aReq.getParameter("method");
if ( method != null && method.equals("addDetails"))
{
addDetails(aReq, aResp);
}
public void addDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
//this method will be called on submitting the form
System.out.println("addDetails");
}
@ProcessAction(name="addDetails")
public void myaddDetails(ActionRequest actionRequest, ActionResponse actionResponse) {
//this method will be called on submitting the form
System.out.println("addDetails");
}