Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java struts中模型驱动的PUT请求问题?_Java_Struts2_Put_Model Driven - Fatal编程技术网

Java struts中模型驱动的PUT请求问题?

Java struts中模型驱动的PUT请求问题?,java,struts2,put,model-driven,Java,Struts2,Put,Model Driven,我正在使用内容类型作为应用程序/x-www-form-urlencoded发出PUT请求。我无法将表单主体元素映射到模型驱动的操作类(User) 以下是一个示例请求: PUT:http://www.xyz.com/account/22424?userName=xyz&email=xyz@email.com 内容类型:application/x-www-form-urlencoded 代码如下: 1)模型驱动的操作类: 公共类用户{ 私人字符串电子邮件; 私有字符串用户名; 公共字符串getUse

我正在使用
内容类型
作为
应用程序/x-www-form-urlencoded
发出PUT请求。我无法将表单主体元素映射到模型驱动的操作类(
User

以下是一个示例请求:

PUT:
http://www.xyz.com/account/22424?userName=xyz&email=xyz@email.com
内容类型:application/x-www-form-urlencoded

代码如下:

1)模型驱动的操作类:

公共类用户{
私人字符串电子邮件;
私有字符串用户名;
公共字符串getUserName(){
返回用户名;
}
public void setUserName(字符串用户名){
this.userName=用户名;
}
公共字符串getEmail(){
回复邮件;
}
公用电子邮件(字符串电子邮件){
this.email=电子邮件;
}
}
2)控制器:

公共类AccountController实现模型驱动{
私有字符串id;
私有用户=新用户();
公共字符串更新(){
user.getUserName();//失败,返回NULL。(应为“xyz”)
}
公共用户getModel(){
返回用户;
}
}

如果您有任何建议,我们将不胜感激。

要将模型映射到表单,您应该实现您已经实现的界面,并配置操作以使用表单

还要确保请求内容与其内容类型和编码相对应