请教,我的actionform怎么拿不到属性字段里的值。拿的全是空值null
//我的actionform
package com.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.crm.hibernate.SalChance;
/**
* MyEclipse Struts
* Creation date: 07-08-2008
*
* XDoclet definition:
* @struts.form name="saleInfoForm"
*/
public class SaleInfoForm extends ActionForm {
/*
* Generated fields
*/
/** chc_linkman property */
/*
* Generated Methods
*/
private SalChance salechance = new SalChance();/*实例化了个SalChance 类*/
public SalChance getSalechance() {
return salechance;
}
public void setSalechance(SalChance salechance) {
this.salechance = salechance;
}
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the chc_linkman.
* @return String
*/
}
/-----------------------
/*查询方法,次方法能让我获得对象并传到页面,页面属性值也能显示*/
public ActionForward doselect(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
SaleInfoForm saleForm = (SaleInfoForm) form;
String chc_id = request.getParameter("id");
SalChance sce = service.findbyid(Long.parseLong(chc_id));
saleForm.setSalechance(sce);
request.setAttribute("saleForm", saleForm);
return mapping.findForward("upsale");
}
/*jsp页面,此页面的property都能从上面的doselect方法中获得值*/
<html:form action="/saleInfo.do?op=dosave" >
<table class="query_form_table">
<tr>
<th>
编号
</th>
<td>
<html:text property="salechance.chcId" />
</td>
<th>
机会来源
</th>
<td>
<html:text property="salechance.chcSource" />
</td>
</tr>
<tr>
<th>
客户名称
</th>
<td>
<html:text property="salechance.chcCustName" />
<span class="red_star">*</span>
</td>
<th>
成功机率(%)
</th>
<td>
<html:text property="salechance.chcRate" />
<span class="red_star">*</span>
</td>
</tr>
<tr>
<th>
概要
</th>
<td colspan="3">
<html:text property="salechance.chcTitle" />
<span class="red_star">*</span>
</td>
</tr>
<tr>
<th>
联系人
</th>
<td>
<html:text property="salechance.chcLinkman" />
</td>
<th>
联系人电话
</th>
<td>
<html:text property="salechance.chcTel" />
</td>
</tr>
<tr>
<th>
机会描述
</th>
<td colspan="3">
<html:textarea property="salechance.chcDesc" />
<span class="red_star">*</span>
</td>
</tr>
<tr>
<th>
创建人
</th>
<td>
<html:text property="salechance.chcCreateBy" readonly="true" />
<span class="red_star">*</span>
</td>
<th>
创建时间
</th>
<td>
<html:text property="salechance.chcCreateDate" readonly="true" />
<span class="red_star">*</span>
</td>
</tr>
</table>
<br />
<table disabled class="query_form_table" id="table1">
<tr>
<th>
指派给
</th>
<td>
<html:select property="salechance.chcDueTo" >
<html:option value="请选择...">请选择...</html:option>
<html:option value="小明">小明</html:option>
<html:option value="旺财">旺财</html:option>
<html:option value="球球">球球</html:option>
<html:option value="孙小美">孙小美</html:option>
<html:option value="周洁轮">周洁轮</html:option>
</html:select>
<span class="red_star">*</span>
</td>
<th>
指派时间
</th>
<td>
<html:text property="salechance.chcDueDate" readonly="true" />
<span class="red_star">*</span>
</td>
</tr>
</table>
</html:form>
/*此dosave方法在上面的页面点击保存后,想直接获得saleForm.getSalechance()这个对象,问题是每次获取都是空,请问为什么*/
public ActionForward dosave(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
SaleInfoForm saleForm = (SaleInfoForm) form;
service.savechance(saleForm.getSalechance());
return new ActionForward("/login.do?opt=dosell");
}
[解决办法]
你的struts-config.xml有问题吧.你在string已经整合了struts所以它里面的path=saleInfo好像是不知道加前面的/
[解决办法]
不应该在前面加/
[解决办法]
不需要用actionForm,用request.setAttribute设置值