I am trying to create a post webservice using jersey. Following is my PostMethod;
@POST
@Path("getEncodedURL")
@Produces(MediaType.TEXT_XML)
public String getEncodedURL(@FormParam(value = "url") String url, @FormParam(value = "eventId") int eventId) {
//mylogic here to get encoded url.
return "<data><eventId>"+eventId+"</eventId><url>"+url+"</url></data>";
}
Following is my index.jsp code.
<form id="form10" method="post">
Enter URL to Encode: (String) <input type="text" name="testName" id="testName">
Event id: (int) <input type="text" name="testEventId" id="testEventId">
<input type="button" Value="Invoke Web Service" onclick="getEncodedURLAgainstURL();">
</form>
function getEncodedURLAgainstURL(){
var testName = $("#testName").val();
var testEventId = $("#testEventId").val();
url = loc+"services/SnapEvent/getEncodedURL";
$.ajax({
type: "post",
url: url,
data:{'eventId': testEventId, 'url': testName},
/* dataType:"text",
contentType: "text/html",*/
success: function(resp){window.location = url},
error: function(e){ alert("An error has occured");}
});
}
when i enter data in form and hit invoke it gives me HTTP Status 405 - Method Not Allowed error. i have debugged it on clicking invoke it goes to the post method and gives error on return.