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 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" /><package name = "default" extends = "struts-default"> <action name = "admincp"> <result>/admin/login.jsp</result> </action> </package>
<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>
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"; }
}
很明显form表单的值传不到给action, HwInfoAction 必须这样写
private HwInfo hwinfo = [b]new HwInfo ()[/b];
public HwInfo getHwinfo()
{
return hwinfo;
}
而HwInfo类的两个属性motherboard和chipset必须提供setXXX和getXXX两种方法
是不是数据库中表字段有必填的
同楼上,如果用Webwork的ioc 是不会创建POjo的
这10分... 分贬值了