Struts 的错误:Exception creating bean of class,如何解决?

J2EE 码拜 10年前 (2015-05-11) 1213次浏览 0个评论
 

我最近在编写基于Struts的程序的时候,运行一个jsp文件:
 
<%@ page language=”java”%>
<%@ taglib uri=”http://jakarta.apache.org/struts/tags-bean” prefix=”bean”%> 
<%@ taglib uri=”http://jakarta.apache.org/struts/tags-html” prefix=”html”%>
<html> 
<head>
<title>JSP for customerEditForm form</title>
</head>
<body>
<html:form action=”/customerEdit”>
<html:hidden property=”id”/>
<html:hidden property=”do” value=”saveCustomer”/>
Name: <html:text property=”name”/><br/>
Last name <html:text property=”lastname”/><br/>
Age <html:text property=”age”/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
出现下面的错误:
description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Exception creating bean of class de.laliluna.library.struts.form.CustomerEditForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.jsp.customerEdit_jsp._jspService(customerEdit_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause 

javax.servlet.jsp.JspException: Exception creating bean of class de.laliluna.library.struts.form.CustomerEditForm: {1}
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
org.apache.jsp.jsp.customerEdit_jsp._jspx_meth_html_form_0(customerEdit_jsp.java:101)
org.apache.jsp.jsp.customerEdit_jsp._jspService(customerEdit_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

我用Goolge搜索,也看到很多人遇到,但是找不到解决的办法。我的代码的编写经过很仔细的检查,应该没有问题的,不知那位大侠遇到过?恳请指教!

de.laliluna.library.struts.form.CustomerEditForm
这个类绝对有的,真是没有搞懂什么回事了。
整了一个下午,终于知道为什么了:
这些代码是根据struts-hibernate-integration-tutorial这个教程实现的源代码写成的,其中de.laliluna.library.struts.form.CustomerEditForm这个类的代码有错误:
//Created by MyEclipse Struts
//XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl

package de.laliluna.library.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import de.laliluna.library.Customer;

/**
 * MyEclipse Struts Creation date: 12-04-2004
 * 
 * XDoclet definition:
 * 
 * @struts:form name=”customerEditForm”
 */
public class CustomerEditForm extends ActionForm {

    private Customer customer;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
问题出在这里:customer没有初始化,因此没有办法对这个变量进行赋值的。
只要改成: private Customer customer=new Customer();
就OK了!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /**
     * @return Returns the customer.
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * @param customer
     *            The customer to set.
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * Method reset
     * 
     * @param mapping
     * @param request
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {

        customer = new Customer();

    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object arg0) {
        return customer.equals(arg0);
    }

    /**
     * @return
     */
    public Integer getAge() {
        return customer.getAge();
    }

    /**
     * @return
     */
    public Integer getId() {
        return customer.getId();
    }

    /**
     * @return
     */
    public String getLastname() {
        return customer.getLastname();
    }

    /**
     * @return
     */
    public String getName() {
        return customer.getName();
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return customer.hashCode();
    }

    /**
     * @param age
     */
    public void setAge(Integer age) {
        customer.setAge(age);
    }

    /**
     * @param id
     */
    public void setId(Integer id) {
        customer.setId(id);
    }

    /**
     * @param lastname
     */
    public void setLastname(String lastname) {
        customer.setLastname(lastname);
    }

    /**
     * @param name
     */
    public void setName(String name) {
        customer.setName(name);
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return customer.toString();
    }
}

100分
你自己解决了,不就没人来要分了吗?

欢迎到这里支持一下:http://www.javawebstudio.com/

帮你顶,我来接吧
本网站和论坛由JavaWebStudio开发组织提供技术支持

webmaster@javawebstudio.com

2004年12月1日启用

论坛还可以


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Struts 的错误:Exception creating bean of class,如何解决?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!