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" /><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>
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,得不到 表单传递过来的值