Invalid property 'stCode' of bean class [java.lang.String]: Bean property 'stCode' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Regist.jsp
<div >
<div >
<div >
<div >
<div >
</div>
<div >
<f:form action="registSave" modelAttribute="r" method="post">
<div >
<div >
<div >
State Name
</div>
</div>
<div >
<div >
<f:input path="stCode" />
</div>
</div>
</div>
<div >
<div >
<div >
District Name
</div>
</div>
<div >
<div >
<f:input path="distCode" />
</div>
</div>
</div>
<div >
<div >
<div >
Phone number
</div>
</div>
<div >
<div >
<f:input path="phone" />
</div>
</div>
</div>
<div >
<div >
<div >
Name
</div>
</div>
<div >
<div >
<f:input path="name" />
</div>
</div>
</div>
<!-- <div >
<input type="email" name="email" id="email" placeholder="Email Address">
</div>
<div >
<div >
<div >
<input type="password" name="password" id="password" placeholder="Password">
</div>
</div>
<div >
<div >
<input type="password" name="password_confirmation" id="password_confirmation" placeholder="Confirm Password">
</div>
</div>
</div> -->
<input type="submit" value="Register" >
</f:form>
</div>
</div>
</div>
</div>
</div>
RBean
package max.Bean;
public class RBean {
String stCode;
String distCode;
String phone;
String name;
public String getStCode() {
return stCode;
}
public void setStCode(String stCode) {
this.stCode = stCode;
}
public String getDistCode() {
return distCode;
}
public void setDistCode(String distCode) {
this.distCode = distCode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Controller
package max;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import max.Bean.RBean;
@Controller
public class MainController {
@Autowired
RBean rBean;
@RequestMapping("home")
public String home()
{
return "registLayout";
}
@RequestMapping("regist")
public ModelAndView registration()
{
return new ModelAndView("reg","r","rBean");
}
@RequestMapping(value="registSave", method=RequestMethod.POST)
public ModelAndView registrationSave(@ModelAttribute("r") RBean rBean)
{
return new ModelAndView("reg","r","rBean");
}
}
CodePudding user response:
if you are trying to set rBean
into r
variable which is available in view then you should remove the "
used for rBean
. Eg: return new ModelAndView("reg","r",rBean);