I have a struts form which i need to submit with Ajax i am not sure how to map parameters of ajax with form. I have created the productMapForm bean class with gatter and setter and also created been in strut-config.xml. I just dont know how to map them in the form and sumbit with Ajax.Request. Thank you so much in advance. And apologies if i have not provided full information.
JSP page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html:html xhtml="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ShoeZone</title>
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
</head>
<body>
<script>
function submitForm() {
var fldName = "Shoe^Product";
var fldtype = "Men's^Shoe";
var userName = "Mike";
var userId = "2232"
var url = "ProductMapAction.do";
var params = "fldname=" + fldName +
"&fldtype=" + fldtype +
"&userName=" + userName +
"&userId=" + userId +
"&formAction=update";
var ajaxRequest = new Ajax.Request(url, {
method: "post",
parameters: params,
asynchronous: true
});
}
</script>
<html:form action="ProductMapAction.do">
<!--
how to map fldName and Fldtype and userName and userId here ???????????????
-->
</html:form>
</body>
</html:html>
ProductMapForm
public class ProductMapForm extends ActionForm {
private String fldname ;
private String fldtype;
private String userName;
private String userId;
private String formAction;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userId) {
this.userId = userId;
}
public String getFldname() {
return fldname;
}
public void setFldname(String fldname) {
this.fldname = fldname;
}
public String getFldtype() {
return fldtype;
}
public void setFldtype(String fldtype) {
this.fldtype = fldtype;
}
public String getFormAction() {
return formAction;
}
public void setFormAction(String formAction) {
this.formAction = formAction;
}
@Override
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
return null;
}
}
Tried like this but getting ERROR
<html:form action="ProductMapAction.do">
<html:hidden property="fldname" value=""/>
<html:hidden property="userName" value=""/>
<html:hidden property="userId" value=""/>
<html:hidden property="formAction" value=""/>
</html:form>
but getting below error
javax.servlet.jsp.JspException: Cannot retrieve definition for form bean ProductMapForm on action ProductMapAction.do
at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:731)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:419)