Discussions

Web tier: servlets, JSP, Web frameworks: Struts name with type problem !!!!!!!!!!!!!!!!!!

  1. Hi all,
    I am getting the problem "Attribute name invalid according to the specified TLD
    " while trying to run "index.jsp" page as follows:


    <html:form action="Lookup" name="lookupForm" type="wiley.LookupForm" >
    <table width="45%" border="0">
    <tr>
    <td>Symbol:</td>
    <td><html:text property="symbol" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><html:submit /></td>
    </tr>
    </table>
    </html:form>

    I had already mentioned the following taglib tag into web.xml:

    <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib>

    <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>

    <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
    </taglib>

    <taglib>
    <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
    </taglib>

    Pls help me out from this problem.

    Thanx in advance
    Regards
    Sachin

    Threaded Messages (9)

  2. wrong attributes[ Go to top ]

    you dont have to specify the html:form action="Lookup" name="lookupForm" type="wiley.LookupForm" >, name and type property. Where as u have to configure in the struts-config.xml
  3. wrong attributes[ Go to top ]

    Thanx Rafi,
    i revomed the type & name attribute, but now i am getting "Cannot retrieve mapping for action /Lookup". here is my struts-config.xml:

    <form-beans>
    <form-bean name="lookupForm"
    type="wiley.LookupForm"/>
    </form-beans>

    <action path="/Lookup"
    type="wiley.LookupAction"
    name="lookupForm"
    input="/index.jsp">
    <forward name="success" path="/quote.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>

    </struts-config>


    Regards
    Sachin
  4. wrong attributes[ Go to top ]

    Hi,
     I guess your web.xml is as follows:
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

    <web-app>
    <display-name>Struts Example Application</display-name>

      <!-- Action Servlet Configuration -->
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>


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



      

      <!-- Struts Tag Library Descriptors -->
      <taglib>
        <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
      </taglib>

      <taglib>
        <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
      </taglib>

      <taglib>
        <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
      </taglib>
      

    </web-app>

    What this file specifies is that the ActionServlet takes care of any url-pattern with *.do. Hence what you need to do in the jsp file is:

    <html>
    <form action="/Lookup.do" >
    ....

    instead of:
    <html>
    <form action="/Lookup" >
    ......

    Try it out.
  5. wrong attributes[ Go to top ]

    Hi Rafi,
    Thanx for your quick reply. I have changed the form as <html:form action="Lookup.do" > as per as your mail and leave the struts-config.xml as it:
    it is:
    <form-beans>
    <form-bean name="lookupForm"
    type="wiley.LookupForm"/>
    </form-beans>

    <action path="Lookup"
    type="wiley.LookupAction"
    name="lookupForm"
    input="/index.jsp">
    <forward name="success" path="/quote.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>

    But no success.May be i am doing some mistake, pls give me a way.

    Regards
    Sachin
  6. wrong attributes[ Go to top ]

    Hi,
     I saw that you are using <html:form> tag. Here's the explanation of what that tag does:
    1) A bean is associated with the form:
     When you use html:form, a bean of the type specified by form-bean is automatically associated with the form. If the scope in the action element is request, a new bean is created each time. If the scope is session, a preexisting bean can be used, if one is found for the current user.

    2) The Web application prefix is prepended automatically:
     That is, you say
    <html:form action="/actions/...">
    to get
    <FORM ACTION="/webAppPrefix/actions/..." ...>.

    3) The .do suffix is appended automatically:
    That is, you say
    <html:form action="/actions/blah">
    to get
    <FORM ACTION="/webAppPrefix/actions/blah.do" ...>.

    4)POST, not GET, is the default METHOD:
     That is, you say
    <html:form action="/actions/blah">
    to get
    <FORM ACTION="/webAppPrefix/actions/blah.do"
          METHOD="POST">.


    So, please try out as follows:
    <html:form action="/Lookup" >
    .....


    and in struts-config.xml:

    <form-beans>
    <form-bean name="lookupForm"
    type="wiley.LookupForm"/>
    </form-beans>

    <action path="/Lookup"
    type="wiley.LookupAction"
    name="lookupForm"
    input="/index.jsp">
    <forward name="success" path="/quote.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>
  7. background of action[ Go to top ]

    Hi,
    You dont have to dxplicitly metion <form action=something.do> rather <form action = something> is enough internally it will be handled. What happend internally is ActionServlet gets the control and look for the matching uri which u have specified in the action tag. If the uri matches, then the actionform for that html is invoked. If you set the validate=true in the action element for that corresponding uri, the validator method will be fired. if the validation succeds it reaches the action class, else the action servlet return the control to the input attribute value which you specified in the action element. This is the reason why we give the input attribute in the action element.

    If you are not sure of this, pls do let me know

    Cheers
    Rafi
  8. Hi Rafi,
    I am getting following execption at my Tomcat console, May be dats why i am getiing "Cannot retrieve mapping for action /Lookup" exception while runing the application.


    Apache Tomcat/4.1.30
    Sep 1, 2004 6:23:15 PM org.apache.commons.digester.Digester error
    SEVERE: Parse Error at line 21 column 17: The content of element type "struts-co
    nfig" must match "(data-sources?,form-beans?,global-exceptions?,global-forwards?
    ,action-mappings?,controller?,message-resources*,plug-in*)".
    org.xml.sax.SAXParseException: The content of element type "struts-config" must
    match "(data-sources?,form-beans?,global-exceptions?,global-forwards?,action-map
    pings?,controller?,message-resources*,plug-in*)".
            at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
    known Source)
            at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown S
    ource)
            at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)

            at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
    n Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
    Dispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
    known Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
            at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
            at org.apache.commons.digester.Digester.parse(Digester.java:1562)
            at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionSe
    rvlet.java:708)
            at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet
    .java:670)
            at org.apache.struts.action.ActionServlet.init(ActionServlet.java:329)
            at javax.servlet.GenericServlet.init(GenericServlet.java:256)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
    java:935)
            at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:82
    3)
            at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
    t.java:3427)
            at org.apache.catalina.core.StandardContext.start(StandardContext.java:3
    628)
            at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)

            at org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
            at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)

            at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363
    )
            at org.apache.catalina.core.StandardService.start(StandardService.java:4
    97)
            at org.apache.catalina.core.StandardServer.start(StandardServer.java:219
    0)
            at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
            at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
            at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
    Sep 1, 2004 6:23:16 PM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
    e
    Sep 1, 2004 6:23:16 PM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
    l=true
    Sep 1, 2004 6:23:18 PM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', retur
    nNull=true
    Sep 1, 2004 6:23:25 PM org.apache.commons.digester.Digester error
    SEVERE: Parse Error at line 30 column 11: The content of element type "web-app"
    must match "(icon?,display-name?,description?,distributable?,context-param*,filt
    er*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-map
    ping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,sec
    urity-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref
    *)".
    org.xml.sax.SAXParseException: The content of element type "web-app" must match
    "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-
    mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welco
    me-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-const
    raint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".
            at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
    known Source)
            at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown S
    ource)







    Regards
    Sachin
  9. Pls correct me .................
    This is my Struts-config.xml as per as Strurs1.1 :


    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

    <struts-config>
    <form-beans>
    <form-bean name="lookupForm" type="wiley.LookupForm" />
    </form-beans>
    <action-mappings>
    <action path="/Lookup" name="lookupForm" className="LookupAction" unknown="false" validate="false" input="/index.jsp" type="wiley.LookupAction">
    <forward name="success" path="/quote.jsp" redirect="false" />
    <forward name="failure" path="/index.jsp" redirect="false" />
    </action>
    </action-mappings>
    </struts-config>


    But i am getting

    Sep 1, 2004 8:32:59 PM org.apache.commons.digester.Digester startElement
    SEVERE: Begin event threw error
    java.lang.NoClassDefFoundError: LookupAction (wrong name: wiley/LookupAction)
    .
    .
    .
    .
    Sep 1, 2004 8:33:10 PM org.apache.commons.digester.Digester error
    SEVERE: Parse Error at line 30 column 11: The content of element type "web-app"
    must match "(icon?,display-name?,description?,distributable?,context-param*,filt
    er*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-map
    ping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,sec
    urity-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref
    *)".
    org.xml.sax.SAXParseException: The content of element type "web-app" must match
    "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-
    mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welco
    me-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-const
    raint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".
            at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
    known Source)


    Pls correct me

    Regards
    Sachin
  10. Now i am getting following exception:

    Sep 1, 2004 10:41:57 PM org.apache.struts.util.RequestUtils createActionForm
    SEVERE: Error creating form bean of class wiley.LookupForm
    java.lang.NullPointerException

    Here is my struts-config.xml:
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

    <struts-config>
    <form-beans>
    <form-bean name="lookupForm" type="wiley.LookupForm" />
    </form-beans>
    <action-mappings>
    <action path="/Lookup" name="lookupForm" validate="false" input="/index.jsp" type="wiley.LookupAction" scope="request">
    <forward name="success" path="/quote.jsp" redirect="false" />
    <forward name="failure" path="/index.jsp" redirect="false" />
    </action>
    </action-mappings>
    <message-resources parameter="wiley.ApplicationResources" />
    </struts-config>

    Does anyone have any idea as to why this is giving me the error:


    Regards
    sachin