谁知道spring mvc中如何使jsp页面中提交的属性自动注入到@Controller注解的类中去呢

@Controller
public class ResultAction {
private Result result;

public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
@RequestMapping("/index.do")
public String queryAllGoods(){
System.out.println(result.getUser()+"===============");
}
}

jsp页面:
<input type="text" name="result.id"/>
<input type="text" name="result.user"/>
<input type="text" name="result.comment"/>

最后始终报空指针,在result的set方法上加@Resource和@Autowired也不行,怎么才能让jsp提交的那些属性注入到ResultAction中呢??

@RequestMapping("/index.do")
public String queryAllGoods(@ModelAttribute Result result){
System.out.println(result.getUser()+"===============");
}
在方法中加上 ModelAttribute注解,spring 会自动把 提交的参数 封装成 model的。
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-10
@RequestMapping("/index.do")
public String queryAllGoods(Result result){
System.out.println(result.getUser()+"===============");
}

试试~~追问

不行的

第2个回答  2012-04-08
你将result保存在request或session中试一下吧
相似回答