cxc3980 2009-03-05 14:09
浏览 259
已采纳

请教问题attempt to create saveOrUpdate event with null

Action中得不到jsp页面表单中的值,大家帮忙看一下哪里错了。
jsp页面:


<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="insert" namespace="/hwinfo">
<s:textfield label="主板" name="hwinfo.motherboard" />
<s:textfield label="芯片" name="hwinfo.chipset" />
<s:submit value="提交" />
</s:form>
</body>
</html>

XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
" -//Apache Software Foundation//DTD Struts Configuration 2.0//EN "
" http://struts.apache.org/dtds/struts-2.0.dtd " >

<struts>
<constant name ="struts.devMode" value = "true" />
<constant name = "struts.configuration.xml.reload" value = "true" />
<constant name = "struts.action.extension" value = "action" />

&lt;package name = "default" extends = "struts-default"&gt; 
    &lt;action name = "admincp"&gt; 
        &lt;result&gt;/admin/login.jsp&lt;/result&gt; 
    &lt;/action&gt;       
&lt;/package&gt; 

<package name = "hwinfo" extends = "struts-default" namespace = "/hwinfo">
<action name="insert" class="hwInfoAction" method="insertHwinfo">
<result name="success">/hwinfo/hardwareinfo.jsp</result>
<result name="input">index.jsp</result>
</action>

</package>
</struts>


Action:

public class HwInfoAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private int hwid;
private String motherboard;
private String chipset;

private HwInfo hwinfo;
private HwInfoDao hwInfoDao;
public void setHwid(int hwid){
    this.hwid=hwid;
}
public int getHwid(){
    return hwid;
}

public void setMotherboard(String motherboard){
    this.motherboard=motherboard;
}
public String getMotherboard(){
    return motherboard;
}

public void setChipset(String chipset ){
    this.chipset=chipset;
}

 public String getChipset(){
        return chipset;
    }

public void setHwInfo(HwInfo hwinfo){
    this.hwinfo=hwinfo;
}
public HwInfo getHwInfo(){
    return hwinfo;
}
public void setHwInfoDao(HwInfoDao hwInfoDao){
    this.hwInfoDao=hwInfoDao;
}
public HwInfoDao getHwInfoDao(){
    return hwInfoDao;
}

public String execute(){
    return "success";
}

public String insertHwinfo(){

    if(hwInfoDao.insertHwinfo(hwinfo))
        return "seccess";
    else
        return "false";
}

}


实在找不出问题了,大家帮忙看看吧!
问题补充:
在action类里面看hwinfo的值,始终是Null,得不到 表单传递过来的值
  • 写回答

3条回答 默认 最新

  • sz_lixu 2009-03-05 18:40
    关注

    很明显form表单的值传不到给action, HwInfoAction 必须这样写
    private HwInfo hwinfo = [b]new HwInfo ()[/b];

    public HwInfo getHwinfo()
    {
    return hwinfo;
    }

    而HwInfo类的两个属性motherboard和chipset必须提供setXXX和getXXX两种方法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?