javajspjavabeansstruts1

Exception creating bean of class


I'm a newbie to struts, have to learn them for work, im using struts 1.3 and I'm trying to make a simple age check app, it doesnt have any business logic as of yet I simply want it to forward to the correct pages I'll figure out the rest later,but im getting the following exception:

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)

The action mapping of 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>

form-bean of struts-config:

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

The welcome.jsp file contents:

<%@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>

The web.xml portion :

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

The action form 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;

    }



}

the 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");
                      }
}

I would greatly appreciate any help with this its frying my brain, thanks in advance

UPDATE:included the Action, also action mapping updated


Solution

  • I finally solved this problem among other ones which followed. The jsp file uses the .do :

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

    The action mapping has no .do :

    <action
                path="/AgeCheck"
                type="coreservlets.CheckAgeAppAction"
                name="AgeCheckForm"
    
                >   
    
                <forward name="UnderAge" path="/UnderAge.jsp" />
    
    
    </action>
    

    Following is the Error I had

    No action instance for path could be created

    This was caused by the file structure of my project which meant that the java files were not being compiled, by default the java files were stored here: Default Location

    I've Moved those exact Files with no changes to here : New Location

    And Hey presto everything works :-) Hopefully this will help someone in future, thanks everyone for help, I can't upvote yet unfortunately.