java - CRUD 应用程序中推送值错误

标签 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——接口(interface) 3) CaseStageDAOImpl - 有四种方法来执行各种 CRUD 操作。 4) CaseStageAction - 实现模型驱动接口(interface) 5) ctsFrmCaseStage.jsp - jsp表单 完成此操作后,我还在 hibernate.cfg.xml 映射部分中包含了 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>

类别.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>

最佳答案

Struts 2 “push” tag is used to push value to the top of stack, so that it can be access or reference easily

  • 您将遇到以下原因导致的错误:

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

解决方案:

您可以在 <s:form 之前的 ctsFrmCaseStage.jsp 页面中添加一个 bean(以指定要压入堆栈的值)像这样的标签:

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

注意:

Struts 2 “bean” tag is used to instantiate a class in the JSP page.

关于java - CRUD 应用程序中推送值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34089285/

相关文章:

java - 在日期中添加天数

java - 当 BigDecimal 已经在 DB (Oracle) 中设置时,指定 BigDecimal 的精度和小数位数是否有意义?

html - like html jsp <form> 类别和子类别格式不支持

java - Spring MVC @RequestMapping 不返回任何内容,只需关闭

java - 在jsp中从mysql获取xml格式的数据

java - 如何使用不同数据库模式的 JPQL?

Java 字符串索引越界

BufferedImage 的 Java 抗锯齿

java - 有没有办法通过 AuditQuery 识别哪些属性已被修改?

java - JPA持久对象异常: detached entity passed to persist