创建类的bean的异常

时间:2016-04-21 11:37:13

标签: java jsp javabeans struts1

我是struts的新手,必须学习他们的工作,我使用struts 1.3并且我试图制作一个简单的年龄检查应用程序,它没有任何业务逻辑,但我只是想要它转发到正确的页面我稍后会弄清楚其余部分,但我得到以下例外:

type Exception report

message An exception occurred processing JSP page /welcome.jsp at line 15

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 /welcome.jsp at line 15

12:         <div style="color:red">
13:             <html:errors />
14:         </div>
15:         <html:form action="/CheckAge.do"  >
16:             User Name : <html:text name="CheckAgeAppForm" property="name" /> <br>
17:             Password  : <html:text name="CheckAgeAppForm" property="age" /> <br>
18:             <html:submit value="Check Age" />


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause 
javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class coreservlets.CheckAgeAppForm: {1}
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:134)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause 
javax.servlet.jsp.JspException: Exception creating bean of class coreservlets.CheckAgeAppForm: {1}
    org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:463)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:433)
    org.apache.jsp.welcome_jsp._jspx_meth_html_005fform_005f0(welcome_jsp.java:169)
    org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:118)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

struts-config的动作映射:

<action-mappings>


<action
    path="/CheckAge"
    type="coreservlets.CheckAgeAppAction"
    name="CheckAgeAppForm"
    scope="session"
    validate="false"
    input="/welcome.jsp">
<forward name="UnderAge" path="/UnderAge.jsp" />
</action>
    <action path="/welcome" forward="/welcome.jsp"/>
</action-mappings>

struts-config的form-b​​ean:

<form-bean
            name="CheckAgeAppForm"
            type="coreservlets.CheckAgeAppForm"/>
    </form-beans>

welcome.jsp文件内容:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <div style="color:red">
            <html:errors />
        </div>
        <html:form action="/CheckAge.do"  >
            User Name : <html:text name="CheckAgeAppForm" property="name" /> <br>
            Password  : <html:text name="CheckAgeAppForm" property="age" /> <br>
            <html:submit value="Check Age" />
        </html:form>
    </body>
</html>

web.xml部分:

<!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

行动表格CheckAgeAppForm:

package coreservlets;

import org.apache.struts.action.*;

public class CheckAgeAppForm extends ActionForm {

    private String name;
    private String age;

    public String getName(){
        return (name);
    }
    public String getAge(){
        return (age);
    }
    public void setName(String name){
        this.name= name;
    }
    public void setAge(String age){
        this.age = age;

    }



}

CheckAgeAppAction:

package coreservlets;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.*;

public class CheckAgeAppAction extends Action
{
            public ActionForward execute(
                      ActionMapping mapping,
                      ActionForm form,
                      HttpServletRequest request,
                      HttpServletResponse response) throws Exception{
                      return mapping.findForward("UnderAge");
                      }
}

我非常感谢任何有关它的帮助我的大脑煎炸,提前谢谢

更新:包含操作,还包括已更新的操作映射

3 个答案:

答案 0 :(得分:1)

如果你发布的Struts配置是你的应用程序,我发现有一个错误,你还没有在你的动作映射中包含转发标记,你已经在转发标记之前关闭了你的行动:

<action
        path="/CheckAge"
        type="coreservlets.CheckAgeAppAction"
        name="CheckAgeAppForm"
        scope="session"
        validate="false"
        input="/welcome.jsp">
    <forward name="UnderAge" path="/UnderAge.jsp" />
</action>

答案 1 :(得分:0)

在您的堆栈跟踪中应该有caused by以下root cause,所以请将其发布。

但无论如何,有一件事对我来说很可疑。你的struts配置有:

<action
        path="/CheckAge"
        type="coreservlets.CheckAgeAppAction"
        ...

type属性的documentation表示:

  

Action子类的完全限定Java类名                        [org.apache.struts.action.Action]将处理请求                        用于此动作映射。如果&#34;转发&#34;                        或&#34;包括&#34;属性已指定。完全是其中之一                        &#34;转发&#34;,&#34;包括&#34;,或&#34;类型&#34;必须指定。

但是在您发布的代码中,您没有上课coreservlets.CheckAgeAppAction - 您只有coreservlets.CheckAgeAppForm。这是一个错误吗?或者你为了简洁而跳过这个?

编辑:好的,错误的痕迹 - 你只是为了简洁而跳过它。对不起,我不知道。

BTW :如果我能给你一些建议,请不要触摸Struts 1.x。如果你必须在你的工作场所使用它,可能最好放弃这份工作。 Struts 1.x非常奇怪且开发人员不友好。此外,自2008年以来也停止了......

答案 2 :(得分:0)

我终于在随后的其他问题中解决了这个问题。 jsp文件使用.do

<html:form action="/AgeCheck.do"  >

动作映射没有.do:

<action
            path="/AgeCheck"
            type="coreservlets.CheckAgeAppAction"
            name="AgeCheckForm"

            >   

            <forward name="UnderAge" path="/UnderAge.jsp" />


</action>

以下是我遇到的错误

  

无法创建路径的动作实例

这是由我的项目的文件结构引起的,这意味着java文件没有被编译,默认情况下java文件存储在这里: Default Location

我已移动那些确切的文件,但没有更改到此处: New Location

嘿,一切都有效:-)希望这将有助于将来, 感谢大家的帮助,不幸的是,我无法支持。