嗨我想使用Ajax與Spring Mvc Porltet在liferay.I有一個Jsp文件和控制器Class.I想要插入一個數據的形式,但我的控制器類沒有調用。所以請幫我解決這個問題。當我點擊提交我的COntroller類不被調用。我想在liferay.I中使用Ajax With Spring Mvc有一個Jsp文件和控制器Class.But控制器類不叫
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects/>
<portlet:resourceURL id="actionOneMethodURL" var="actionOneMethodURL">
</portlet:resourceURL>
<head>
<script type="text/javascript">
function namet()
{
alert("in the function");
var name = document.getElementById('<portlet:namespace/>name').value;
var age = document.getElementById('<portlet:namespace/>age').value;
var email = document.getElementById('<portlet:namespace/>email').value;
jQuery.ajax({
url : "<%=actionOneMethodURL%>",
datatype : 'POST',
data : {
reqname : name,
reqage : age,
reqemail: email,
},
success : function(response)
{
},
});
}
</script>
</head>
</html>
<body>
<form method="post" id='<portlet:namespace/>fm' name='<portlet:namespace/>fm'>
<div class="control-group">
<label class="control-label" for="name">Name:</label>
<div class="controls">
<input name="<portlet:namespace/>name" id="<portlet:namespace/>name" class="field-required" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Age">Age:</label>
<div class="controls">
<input name="<portlet:namespace/>age" id="<portlet:namespace/>age" class="field-required" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">Email:</label>
<div class="controls">
<input name="<portlet:namespace/>email" id="<portlet:namespace/>email" class="field-required" type="text">
</div>
</div>
<input class="btn btn-info" type="button" value="save" name="action" onclick="namet()">
<input class="btn btn-primary" type="reset" value="Reset">
</form>
</body>
</html>
Here Is my Jsp File...
package com.hrms;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import com.hrms.model.HRMS;
import com.hrms.service.HRMSLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;
@Controller(value = "HrmsController")
@RequestMapping("VIEW")
public class HrmsController {
@RenderMapping
public String handleRenderRequest(RenderRequest request,
RenderResponse response, Model model) {
return "view";
}
@ResourceMapping(value="actionOneMethodURL")
public void actionOneMethodURL(ResourceRequest request,ResourceResponse response) throws SystemException, IOException {
System.out.println("In the Method");
int id = 0;
id = (int) CounterLocalServiceUtil.increment(HrmsController.class.getName());
String reqname = ParamUtil.getString(request, "reqname");
String reqage = ParamUtil.getString(request, "reqage");
String reqemail = ParamUtil.getString(request, "reqemail");
HRMS hrms = null;
hrms = HRMSLocalServiceUtil.createHRMS(id);
hrms.setName(reqname);
hrms.setAge(reqage);
hrms.setEmail(reqemail);
hrms = HRMSLocalServiceUtil.updateHRMS(hrms);
HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
ServletResponseUtil.write(httpServletResponse, response.toString());
}
}
and here is my Controller Class...
我做到這一點的變化,但仍然沒有工作.. \t jQuery.ajax({ \t \t URL:「<%= actionOneMethodURL.toString ()%>」, \t \t類型: 'POST', \t \t數據:{ \t \t \t名:姓名, \t \t \t年齡:年齡, \t \t \t電子郵件:電子郵件, \t \t \t}, \t \t}); } –
你有控制器中的任何方法註解@ResourceMapping? –
是的,我描述了我的控制器。 –