facebook

Configuration Issue with Struts

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #247013 Reply

    Russ
    Member

    I very new to struts and I am learning under fire. I have all the parts working now but I am unable to present the information to the screen. I am a little fuzzy on this part of the application. I am not sure I have the mappings right. Can someone be so kind to point out my issue?

    Eclipse version: 3.1.1

    workbench version: 4.1

    Application server: JBoss4.0.3SP1

    Struts verion: what ever comes with workbench

    Error throw inside jsp:

    
    [13:07:34,781] [ERROR] [[jsp]] Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Cannot retrieve mapping for action /AddCatalogEntry
        at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:810)
        at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
        at org.apache.jsp.AddJournal_jsp._jspx_meth_html_form_0(org.apache.jsp.AddJournal_jsp:346)
        at org.apache.jsp.AddJournal_jsp._jspService(org.apache.jsp.AddJournal_jsp:195)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)
    
    

    The struts-config.xml

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!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>
      <data-sources />
      <form-beans>
        <form-bean name="CatalogForm" type="com.rrcorp.formbean.CatalogForm" />
      </form-beans>
    
      <global-exceptions />
      <global-forwards />
      
      <action-mappings >
        <action
          attribute="CatalogForm"
          input="/AddJournal.jsp"
          name="CatalogForm"
          path="/AddJournal"
          scope="request"
          type="com.rrcorp.action.AddCatalogEntry">
          <forward name="success" path="/AddJournal.jsp" />
          <forward name="failure" path="/AddJournal.jsp" />
        </action>
      </action-mappings>
      
      <controller bufferSize="4096" debug="0"/>
      
      <message-resources parameter="com.rrcorp.struts.ApplicationResources" />
      
       <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                      /WEB-INF/validation.xml"/>
       </plug-in>
    </struts-config>
    

    The web.xml

    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
    
      <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>
        <init-param>
          <param-name>debug</param-name>
          <param-value>3</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>3</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
          <welcome-file>/AddJournal.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    
    
    #247015

    Russ
    Member

    forgot to post jsp.

    AddJournal.jsp

    
    
    <%@ page language="java" pageEncoding="UTF-8"%>
    
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    
    <%@ page import="com.rrcorp.hibernate.CatalogService" %>
    <%@ page import="java.util.List" %>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
       <head>
        <title>Catalog Eample </title>
        <html:base/>
       </head>
      <body bgcolor="white">
        <h3>Catalog Example</he>
        <html:errors/>
        <%
        /*
         * This code will generate a list of objects from the 
         * database and place a reference to this list in the
         * request object 
         *
         */
         System.out.println("Going to get data from the database");
         List catalogList = CatalogService.getInstance().getCatalogList();
         System.out.println("Back from the database");
         request.setAttribute("catalog", catalogList);
        %>
        <p> List of Catalog items in <code> Catalog</code> table of database <code> test</code>.</p>
      
        <table border=1>
          <logic:iterate id="element" name="catalog" scope="request" type="com.rrcorp.hibernate.Catalog">
          <tr>
             <td><bean:write name="element" property="journal" /></td>
             <td><bean:write name="element" property="publisher" /></td>
             <td><bean:write name="element" property="date" /></td>
             <td><bean:write name="element" property="title" /></td>
             <td><bean:write name="element" property="author" /></td>
         </logic:iterate>
        </table>
        
        <p> Submit to add Catalog entry. </p>
        
        <!-- This form will post the submitted data to the AddJournal Action Mapping -->
        <html:form action="/AddCatalogEntry" method="post">
          <table border=1>
            <tr><td>Journal Name:</td><td><html:text property="journalName"/></td>
            <tr><td>Publisher:</td><td><html:text property="publisher"/></td>
            <tr><td>Date:</td><td><html:text property="date"/></td>
            <tr><td>Title:</td><td><html:text property="title"/></td>
            <tr><td>Author:</td><td><html:text property="author"/></td>
          </table><br/>
          <html:submit/>
         </html:form>
      </body>
    </html:html>
    
    #247018

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

    The way struts works is when you visit a page with a .do (or whatever mapping you made it) extension, ActionServlet rips off the .do extension, then tries to match the remaining name, in this case “AddCatalogEntry” to an entry in your struts-config.xml file. Unfortunately you don’t have an entry with that name, you only have: path=”/AddJournal”

    so you either need to change the name of your action-mapping or add a new mapping that will match against the form’s name. Or just change the target of your form.

    #247030

    Russ
    Member

    That did it…….fixed right the first time…… Just changed the path name to /AddCatalogEntry and every thing worked just right……..

    Thank you!

    #247031

    Riyad Kalla
    Member

    Glad to hear it, Struts gets some getting used to with that mapping business, but once you get over that hump it’s smooth sailing.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Configuration Issue with Struts

You must be logged in to post in the forum log in