Struts2使用模型驱动ModelDriven不能装在模型属性

Action代码:

public class ProductAction extends ActionSupport implements ModelDriven<Product> {


 /**
  *
  */
 private static final long serialVersionUID = -2947866505600195157L;
 //模型驱动使用的类
 private Product product = new Product();
 
 @Override
 public Product getModel() {
  return product;

JSP代码:

<s:form action="product_save" method="post" namespace="/" theme="simple">
 <table border="1" width="400">
  <tr>
   <td>商品的名称</td>
   <td><input name="pName"/></td>
  </tr>
  <tr>
   <td>商品的价格</td>
   <td><input name="pPrice"/></td>
  </tr>
  <tr>
   <td colspan="2"><input type="submit" value="添加"/></td>
  </tr>
 </table>
</s:form>


qq_静静的垭口_03935456
浏览 3333回答 5
5回答

qq_静静的垭口_03935456

解决了,实体属性名的问题,属性命名第一个和第二个字母不能大写;看看我eclipse生成的getter和setter方法,和struts2拦截器通过页面form表单中的属性名封装得到的getter和setter对应不上导致的,struts2拦截器通过页面属性封装得到的getter和setter为getPName(),setPName()。将实体属性名改成全小写,问题解决

qq_静静的垭口_03935456

JSP代码

大咪

你把这里改成s标签库试试   <td>商品的名称</td>    <td><input name="pName"/></td>//这里改成<s:text name="pName"/>   </tr>   <tr>    <td>商品的价格</td>    <td><input name="pPrice"/></td>//这里也是,然后你试试   </tr>   因为你就是想传值,得用到s标签,先试试看看行不.

大咪

吧报错信息截图上来看看
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java