struts2 form提交对象有的接收过来是null呢?

coolzdp 2012-08-07 08:35:55
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<form action="add.action" method="post" name="form1">
<input type="text" name="book.name"/>
<input type="text" name="book.author"/>
<input type="text" name="book.price"/>
<input type="submit">
</form>
</body>
</html>

传到后台private Book book 里
只有price有值,name,author都为null,是咋回事呢.get set都有的?
...全文
377 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
宏Lee 2012-08-08
  • 打赏
  • 举报
回复
在把你action的代码贴出来
一叶飞舟 2012-08-08
  • 打赏
  • 举报
回复
应该用struts2的表单<s:form></s:form>,然后在action写set和get方法,普通的表单不行!
jackson_fighting 2012-08-08
  • 打赏
  • 举报
回复
<form action="add.action" method="post" name="form1">
<input type="text" name="book.name"/>
<input type="text" name="book.author"/>
<input type="text" name="book.price"/>
<input type="submit">
</form>
只是struts2的表单?
<s:form></s:form>.....
coolzdp 2012-08-08
  • 打赏
  • 举报
回复
public class Book {
private int id;
private String name;
private String author;
private int price;
private String addtime;

public String getAddtime() {
return addtime;
}
public void setAddtime(String addtime) {
this.addtime = addtime;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}

}
zzlovelyboy 2012-08-07
  • 打赏
  • 举报
回复
你可以先试一下那个属性传值的方法。。。如果还不行的话,那就是要重新把你的工程的流程看一下。。
guangtime 2012-08-07
  • 打赏
  • 举报
回复
你确定你book的属性没写错?
宏Lee 2012-08-07
  • 打赏
  • 举报
回复
把你book类贴出来看哈

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧