请求路径为:  http://localhost:8080/SKPlatfrom/toEditCategory.action?category.id=1=========================================================================================
package com.sk.systemInfo.action;import java.util.Date;
import java.util.Map;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sk.systemInfo.domain.Category;
import com.sk.systemInfo.domain.SystemUser;
import com.sk.systemInfo.service.CategoryService;public class CategoryAction extends ActionSupport implements Action {

/**注入categoryService*/
private CategoryService categoryService;
public CategoryService getCategoryService() {
return categoryService;
} public void setCategoryService(CategoryService categoryService) {
this.categoryService = categoryService;
}


private Category category;
public Category getCategory() {
return category;
} public void setCategory(Category category) {
this.category = category;
}
public String toEdit() {
//1.根据请求的编号查询类别信息
category = categoryService.findById(category.getId());
//2.获取session
Map session = ActionContext.getContext().getSession();
//3.保存到session
session.put("category", category);
return "toEdit";
}
}
==========================================================================================================
package com.sk.systemInfo.domain;import java.sql.Timestamp;
import java.util.Date;/**
 * Category entity. @author MyEclipse Persistence Tools
 */public class Category implements java.io.Serializable { // Fields
//org.extremecomponents.table.cell.FilterDroplistCell
private Integer id;
private String type1;
private String type2;
private String type3;
private String flag;
private String crtuser;
private Date crtdate;
private String upduser;
private Date upddate; // Constructors /** default constructor */
public Category() {
} /** full constructor */
public Category(String type1, String type2, String type3, String flag,
String crtuser, Timestamp crtdate, String upduser, Timestamp upddate) {
this.type1 = type1;
this.type2 = type2;
this.type3 = type3;
this.flag = flag;
this.crtuser = crtuser;
this.crtdate = crtdate;
this.upduser = upduser;
this.upddate = upddate;
} // Property accessors public Integer getId() {
return this.id;
} public void setId(Integer id) {
this.id = id;
} public String getType1() {
return this.type1;
} public void setType1(String type1) {
this.type1 = type1;
} public String getType2() {
return this.type2;
} public void setType2(String type2) {
this.type2 = type2;
} public String getType3() {
return this.type3;
} public void setType3(String type3) {
this.type3 = type3;
} public String getFlag() {
return this.flag;
} public void setFlag(String flag) {
this.flag = flag.trim();
} public String getCrtuser() {
return this.crtuser;
} public void setCrtuser(String crtuser) {
this.crtuser = crtuser;
} public Date getCrtdate() {
return this.crtdate;
} public void setCrtdate(Date crtdate) {
this.crtdate = crtdate;
} public String getUpduser() {
return this.upduser;
} public void setUpduser(String upduser) {
this.upduser = upduser;
} public Date getUpddate() {
return this.upddate;
} public void setUpddate(Date upddate) {
this.upddate = upddate;
}}
==========================================================================================================请求路径为:  http://localhost:8080/SKPlatfrom/toEditCategory.action?category.id=1
的时候  为什么在action中  category.getId()  为null

解决方案 »

  1.   

    感觉id没有传进来,会不会是因为struts2是把id=1看成字符串或者int类型,而不是Integer,所以没有实例Integer的对象,id仍然是空的
      

  2.   

    在这里贴一下我的问题,因为没有分,所以没有人回答,借贵地人气一问
    收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 怎样把Action的处理结果填充到页面的输入框内,显示后输入框仍然是可编辑的
      

  3.   

    楼主:    传值方式没有问题。    把toEditCategory在struts.xml中配置贴出来看看。
      

  4.   

    <action name="*Supplier" class="com.sk.supplier.action.SupplierAction" method="{1}">
    <interceptor-ref name="checkSession"/>
    <result name="success">/WEB-INF/pages/supplier/supplierList.jsp</result>
    <result name="toAdd">/WEB-INF/pages/supplier/supplierAdd.jsp</result>
    <result name="toEdit">/WEB-INF/pages/supplier/supplierEdit.jsp</result>
    <result name="toLogin">/index2.jsp</result>
    </action>
    ============================================================
    这是struts.xml中的配置
      

  5.   

    原因已经找到   是用了struts2的拦截器的问题 我想问下  拦截器 和  这个会冲突么   应该要怎么解决
    public String intercept (ActionInvocation invocation) throws Exception {
    Map session = this.getSession();
    if (session.get("loginUser") == null) {
    return "toLogin";
    } else {
    return invocation.invoke();
    }
    }
    以上为拦截器代码
      

  6.   

    不冲突。在Action配置中引用自己定义的拦截器,还必须引用defaultStack(系统默认),系统不会自动引用。
    这就是产生错误的原因。