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

请教问题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 django5安装失败
  • ¥60 ios系统storm sniffer 写入http规则加密如何破解?
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译