CRUD应用程序中的推送值错误

时间:2015-12-04 13:17:18

标签: java hibernate jsp struts2

我正在研究CRUD应用程序,我应该设计多种形式。我试图根据可用的示例here对应用程序进行建模。 我能够设计第一个表格而没有任何问题。但我面临第二种形式的跟随错误

type Exception report
message An exception occurred processing JSP page /ctsFrmCaseStage.jsp at     line 22
description The server encountered an internal error that prevented it from    fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page     /ctsFrmCaseStage.jsp at line 22
19: </head>
20: <body>
21: <s:form action="saveOrUpdateCaseStage">
22:     <s:push value="casestage">
23:         <s:hidden name="ccs_ID" />
24:         <s:textfield name="ccs_CaseStageName" label="CaseStage Name" />
25:                 <s:textfield name="ccs_Description" label="Description"   />

root cause

tag 'push', field 'value': You must specify a value to push on the stack.   Example: person - [unknown location]
org.apache.struts2.components.Component.fieldError(Component.java:230)
org.apache.struts2.components.Component.findValue(Component.java:351)
org.apache.struts2.components.Push.start(Push.java:128)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupp    ort.java:53)

我采取了以下步骤来设计此表单 - 1)CaseStage.Java这是我的域对象 2)CaseStageDAO - 界面 3)CaseStageDAOImpl - 有四种方法来执行各种CRUD操作。 4)CaseStageAction - 实现模型驱动的接口 5)ctsFrmCaseStage.jsp - jsp表单 完成后 - 我还在hibernate.cfg.xml Mappings部分中包含了CaseStage类。 我想知道我错过了什么...请注意我对struts和hibernate世界很新。非常感谢你提前 以下是所有

的顺序代码

CaseStage.java

package com.tutorials4u.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "mcasecategory")
public class CaseStage {
private Long ccs_ID;
private int ccs_StageName, ccs_Description;

@Id
@GeneratedValue
@Column(name = "ccs_ID") 
public Long getCcs_ID() {
    return ccs_ID;
}

public void setCcs_ID(Long ccs_ID) {
    this.ccs_ID = ccs_ID;
}

@Column(name = "ccs_StageName")
public int getCcs_StageName() {
    return ccs_StageName;
}

public void setCcs_StageName(int ccs_StageName) {
    this.ccs_StageName = ccs_StageName;
}

@Column(name = "ccs_Description")
public int getCcs_Description() {
    return ccs_Description;
}

public void setCcs_Description(int ccs_Description) {
    this.ccs_Description = ccs_Description;
}


}

CaseStage.DAO

package com.tutorials4u.dao;
import java.util.List;

import com.tutorials4u.domain.CaseStage;


public interface CaseStageDAO {
public List<CaseStage> listCaseStage();
public void saveOrUpdateCaseStage(CaseStage casestage);
public CaseStage listCaseStageById(Long casestageId);
public void deleteCaseStage(Long casestageId);
}

CaseStageDAOImpl.java

package com.tutorials4u.dao;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import com.tutorials4u.domain.CaseStage;


public class CaseStageDAOImpl implements CaseStageDAO {
@SessionTarget
Session session;

@TransactionTarget
Transaction transaction;

    /**
 * Used to save or update a casestage.
 */
@SuppressWarnings("unchecked")
public List<CaseStage> listCaseStage() {
    List<CaseStage> courses = null;
    try {
        courses = session.createQuery("from CaseStage").list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return courses;
}

    public void saveOrUpdateCaseStage(CaseStage casestage) {
    try {
        session.saveOrUpdate(casestage);
    } catch (Exception e) {
        transaction.rollback();
        e.printStackTrace();
    }
}

    /**
 * Used to delete a user.
 */
public void deleteCaseStage(Long casestageId) {
    try {
        CaseStage casestage = (CaseStage) session.get(CaseStage.class, casestageId);
        session.delete(casestage);
    } catch (Exception e) {
        transaction.rollback();
        e.printStackTrace();
    } 
}

/**
 * Used to list all the users.
 */

/**
 * Used to list a single user by Id.
 */
public CaseStage listCaseStageById(Long casestageId) {
    CaseStage casestage = null;
    try {
        casestage = (CaseStage) session.get(CaseStage.class, casestageId);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return casestage;
}
}

CaseStageAction.java

package com.tutorials4u.web;

import static com.opensymphony.xwork2.Action.SUCCESS;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tutorials4u.dao.CaseStageDAO;
import com.tutorials4u.dao.CaseStageDAOImpl;
import com.tutorials4u.domain.CaseStage;

public class CaseStageAction extends ActionSupport implements ModelDriven<CaseStage> {

private static final long serialVersionUID = -6659925652584240539L;

private CaseStage casestage = new CaseStage();
private List<CaseStage> casestageList = new ArrayList<CaseStage>();
private CaseStageDAO casestageDAO = new CaseStageDAOImpl();

public CaseStage getModel() {
    return casestage;
}

/**
 * To save or update casestage.
 * @return String
 */
    public String saveOrUpdate()
{   
    casestageDAO.saveOrUpdateCaseStage(casestage);
    return SUCCESS;
}

/**
 * To list all categories.
 * @return String
 */
public String list()
{
    casestageList = casestageDAO.listCaseStage();
    return SUCCESS;
}

/**
 * To delete a casestage.
 * @return String
 */
    public String delete()
{
    HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
    casestageDAO.deleteCaseStage(Long.parseLong(request.getParameter("ccs_ID")));
    return SUCCESS;
}
/**
 * To list a single casestage by Id.
 * @return String
 */
    public String edit()
{
    HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
    casestage = casestageDAO.listCaseStageById(Long.parseLong(request.getParameter("ccs_ID")));
    return SUCCESS;
}

public CaseStage getCaseStage() {
    return casestage;
}

public void setCaseStage(CaseStage casestage) {
    this.casestage = casestage;
}

public List<CaseStage> getCaseStageList() {
    return casestageList;
}

public void setCaseStageList(List<CaseStage> casestageList) {
    this.casestageList = casestageList;
}

}

ctsFrmCaseStage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Page</title>
<s:head />
<style type="text/css">
@import url(style.css);
</style>
</head>
<body>
<s:form action="saveOrUpdateCaseStage">
<s:push value="casestage">
    <s:hidden name="ccs_ID" />
    <s:textfield name="ccs_CaseStageName" label="CaseStage Name" />
            <s:textfield name="ccs_Description" label="Description" />

            <s:submit />
</s:push>
</s:form>

<s:if test="casestageList.size() > 0">
<div class="content">
<table class="userTable" cellpadding="5px">
    <tr class="even">
        <th>CaseStage Name</th>
        <th>Description</th>


    </tr>
    <s:iterator value="casestageList" status="casestageStatus">
        <tr
            class="<s:if test="#casestageStatus.odd == true ">odd</s:if>  <s:else>even</s:else>">
            <td><s:property value="ccs_CaseStageName" /></td>
            <td><s:property value="ccs_Description" /></td> 

                            <td><s:url id="editURL" action="editCaseStage">
                                    <s:param name="ccs_ID" value="%{ccs_ID}"></s:param>
            </s:url> <s:a href="%{editURL}">Edit</s:a></td>
            <td><s:url id="deleteURL" action="deleteCaseStage">
                <s:param name="ccs_ID" value="%{ccs_ID}"></s:param>
            </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
        </tr>
    </s:iterator>
</table>
</div>
</s:if>
</body>
</html>

Category.java

package com.tutorials4u.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "cts_mcasecategory")
public class Category {

private Long ccg_ID;
private int ccg_CreateUser, ccg_ModifyUser;
private String ccg_CategoryName;
private String ccg_Description;
private Date ccg_CreateDate, ccg_ModifyDate;
private boolean ccg_DeleteFlag, ccg_ActiveFlag;

@Id
@GeneratedValue
@Column(name = "ccg_ID")    
public Long getCcg_ID() {
    return ccg_ID;
}

public void setCcg_ID(Long ccg_ID) {
    this.ccg_ID = ccg_ID;
}

@Column(name = "ccg_CategoryName")    
public String getCcg_CategoryName() {
    return ccg_CategoryName;
}

public void setCcg_CategoryName(String ccg_CategoryName) {
    this.ccg_CategoryName = ccg_CategoryName;
}

@Column(name = "ccg_Description")    
public String getCcg_Description() {
    return ccg_Description;
}

public void setCcg_Description(String ccg_Description) {
    this.ccg_Description = ccg_Description;
}

@Column(name = "ccg_CreateUser")
public int getCcg_CreateUser() {
    return ccg_CreateUser;
}

public void setCcg_CreateUser(int ccg_CreateUser) {
    this.ccg_CreateUser = ccg_CreateUser;
}

@Column(name = "ccg_ModifyUser")
public int getCcg_ModifyUser() {
    return ccg_ModifyUser;
}

public void setCcg_ModifyUser(int ccg_ModifyUser) {
    this.ccg_ModifyUser = ccg_ModifyUser;
}

@Column(name = "ccg_CreateDate")
public Date getCcg_CreateDate() {
    return ccg_CreateDate;
}

public void setCcg_CreateDate(Date ccg_CreateDate) {
    this.ccg_CreateDate = ccg_CreateDate;
}

@Column(name = "ccg_ModifyDate")
public Date getCcg_ModifyDate() {
    return ccg_ModifyDate;
}

public void setCcg_ModifyDate(Date ccg_ModifyDate) {
    this.ccg_ModifyDate = ccg_ModifyDate;
}

@Column(name = "ccg_DeleteFlag")
public boolean isCcg_DeleteFlag() {
    return ccg_DeleteFlag;
}

public void setCcg_DeleteFlag(boolean ccg_DeleteFlag) {
    this.ccg_DeleteFlag = ccg_DeleteFlag;
}

@Column(name = "ccg_ActiveFlag")
public boolean isCcg_ActiveFlag() {
    return ccg_ActiveFlag;
}

public void setCcg_ActiveFlag(boolean ccg_ActiveFlag) {
    this.ccg_ActiveFlag = ccg_ActiveFlag;
}
}

Hibernate配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/case_tracking_system    </property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">nvj@123</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="com.tutorials4u.domain.User"/>
<mapping class="com.tutorials4u.domain.Category"/>
<mapping class="com.tutorials4u.domain.CaseStage"/>
</session-factory>
</hibernate-configuration>

struts.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate   Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/case_tracking_system    </property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">nvj@123</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="com.tutorials4u.domain.User"/>
<mapping class="com.tutorials4u.domain.Category"/>
<mapping class="com.tutorials4u.domain.CaseStage"/>
</session-factory>
</hibernate-configuration>

1 个答案:

答案 0 :(得分:1)

  

Struts 2“push”标签用于将值推到堆栈顶部,这样   它可以轻松访问或参考

  • 您将遇到错误:

    tag 'push', field 'value': You must specify a value to push on the stack.     Example: person - [unknown location]
    

解决方案:

Yo可以在{strong> ctsFrmCaseStage.jsp 页面中添加一个bean(以指定要在堆栈上推送的值),然后再添加<s:form标记:

<body>
<s:bean name="com.tutorials4u.domain.CaseStage" var="casestage" />
<s:form action="saveOrUpdateCaseStage">
<s:push value="casestage">

NB:

  

Struts 2“bean”标记用于在JSP页面中实例化一个类。