You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Iraklis Kourtidis <ik...@covia.com> on 2001/04/06 01:56:49 UTC

.do mappings not working & bean cannot be read by the JSP

How are you gentlemen!! Somebody set up me the bomb.

I have installed Struts OK, and I've even run the 'struts-example'
application (which means that Struts is working fine with me otherwise.) I'm
trying to create a small application, but I am having problems.

When I type
http://localhost:7001/myapp/listDirectoryContents.do
in the browser, I get a 'page not found'. If I change 'do' to something else
(such as "foo"), I get a Error 404--Not Found, which means that at least the
'action' servlet is called... I am appending my web.xml and
struts-config.xml: for the life of me I can't spot anything wrong about
them.

A second problem that I've wasted my youth on is that my action class adds
an object (bean, if you wish) to the request or session by the following:

HttpSession session = request.getSession();
session.setAttribute("com.covia.struts.folder_contents", di);

or
request.setAttribute("com.covia.struts.folder_contents", di);

(I'm saying 'or' because I've tried both.)

In my JSP I've used the following line:
<logic:iterate id="aFile" name="com.covia.struts.folder_contents"
property="fileroomFolders" scope="session">
 ...

to access this bean, but I get a message saying
<Apr 5, 2001 6:32:56 PM CDT> <Error> <HTTP>
<[WebAppServletContext(2243896,fileroom_struts)] Root cause of
ServletException
javax.servlet.jsp.JspException: Cannot find bean
com.covia.struts.folder_contents in scope session

Again, I've tried this using both 'session' and 'request' scope.

My understanding has been that the action class gets called first. It places
whatever it needs on the request/session, and then the JSP file that's
listed in struts-config.xml as its 'input' runs right afterwards. Did I get
something wrong?

Infinite thanks to whoever can help me with this! I've already wasted a ton
of time - to no avail - trying to solve this.
thanks much,
Iraklis


****************************************************************************
****
<?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>

  <!-- 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>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>0</param-value>
    </init-param>
    <init-param>
      <param-name>validate</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>


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


  <!-- The Welcome File List -->
  <welcome-file-list>
    <welcome-file>welcome.jsp</welcome-file>
  </welcome-file-list>

  <!-- 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>

****************************************************************************
****

<?xml version="1.0" encoding="ISO-8859-1" ?>

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

<struts-config>

  <data-sources/>

  <!-- ========== Form Bean Definitions
=================================== -->
  <form-beans>

    <!-- Logon form bean -->
    <form-bean      name="listDirForm"

type="com.covia.struts.actionforms.ListDirectoryContentsForm"/>

  </form-beans>


  <!-- ========== Global Forward Definitions
============================== -->
  <global-forwards/>


  <!-- ========== Action Mapping Definitions
============================== -->
  <action-mappings>

    <action    path="/listDirectoryContents"
               type="com.covia.struts.actions.ListDirectoryContentsAction"
               name="listDirForm"
              scope="request"
           validate="false">
      <forward name="listDirectoryContents"
path="/listDir.jsp"/>
	</action>
  </action-mappings>

</struts-config>


RE: .do mappings not working & bean cannot be read by the JSP

Posted by Iraklis Kourtidis <ik...@covia.com>.
thanks Maya. I've tried all the steps you just mentioned unfortunately. I've
gone through the struts-example back and forth. The one thing that was
completely not clear was what happens first - the execution of the code in
the Action, or the displaying of the JSP? Anyway, thanks much for the help.
Iraklis

-----Original Message-----
From: mmuchnik [mailto:mmuchnik]On Behalf Of Maya Muchnik
Sent: Friday, April 06, 2001 8:10 AM
To: struts-user@jakarta.apache.org
Subject: Re: .do mappings not working & bean cannot be read by the JSP


Iraklis,

I will try to help you, but maybe I could not, because, I am almost in the
start stage as you are. The first you need to understand HOW struts-example
works, you can find "A Walk tour .." in the example menu. This tour explains
step by step, what involve and how in struts-example. The second COMPARE
your
struts-config.xml and the example. How the example is starting - from
<welcome-file-list> file, that is index.jsp. And index.jsp is calling
logon.jsp
for logon.do action. And so on.

My point is this - you cannot call
http://localhost:7001/myapp/listDirectoryContents.do
directly from a browser, it must be through some start file. Where is your
"welcome.jsp"?

Your do not have an application resource file, maybe it is OK. Because you
do
not want to check anything.

The second, Action class is called by ActionServlet, if the servlet is found
that this action must to be performed according to ActionForm submitted
through
a request.

Maya

Iraklis Kourtidis wrote

> How are you gentlemen!! Somebody set up me the bomb.
>
> I have installed Struts OK, and I've even run the 'struts-example'
> application (which means that Struts is working fine with me otherwise.)
I'm
> trying to create a small application, but I am having problems.
>
> When I type
> http://localhost:7001/myapp/listDirectoryContents.do
> in the browser, I get a 'page not found'. If I change 'do' to something
else
> (such as "foo"), I get a Error 404--Not Found, which means that at least
the
> 'action' servlet is called... I am appending my web.xml and
> struts-config.xml: for the life of me I can't spot anything wrong about
> them.
>
> A second problem that I've wasted my youth on is that my action class adds
> an object (bean, if you wish) to the request or session by the following:
>
> HttpSession session = request.getSession();
> session.setAttribute("com.covia.struts.folder_contents", di);
>
> or
> request.setAttribute("com.covia.struts.folder_contents", di);
>
> (I'm saying 'or' because I've tried both.)
>
> In my JSP I've used the following line:
> <logic:iterate id="aFile" name="com.covia.struts.folder_contents"
> property="fileroomFolders" scope="session">
>  ...
>
> to access this bean, but I get a message saying
> <Apr 5, 2001 6:32:56 PM CDT> <Error> <HTTP>
> <[WebAppServletContext(2243896,fileroom_struts)] Root cause of
> ServletException
> javax.servlet.jsp.JspException: Cannot find bean
> com.covia.struts.folder_contents in scope session
>
> Again, I've tried this using both 'session' and 'request' scope.
>
> My understanding has been that the action class gets called first. It
places
> whatever it needs on the request/session, and then the JSP file that's
> listed in struts-config.xml as its 'input' runs right afterwards. Did I
get
> something wrong?
>
> Infinite thanks to whoever can help me with this! I've already wasted a
ton
> of time - to no avail - trying to solve this.
> thanks much,
> Iraklis
>
>
****************************************************************************
> ****
> <?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>
>
>   <!-- 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>
>     <init-param>
>       <param-name>debug</param-name>
>       <param-value>2</param-value>
>     </init-param>
>     <init-param>
>       <param-name>detail</param-name>
>       <param-value>0</param-value>
>     </init-param>
>     <init-param>
>       <param-name>validate</param-name>
>       <param-value>false</param-value>
>     </init-param>
>     <load-on-startup>2</load-on-startup>
>   </servlet>
>
>   <!-- Action Servlet Mapping -->
>   <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*.do</url-pattern>
>   </servlet-mapping>
>
>   <!-- The Welcome File List -->
>   <welcome-file-list>
>     <welcome-file>welcome.jsp</welcome-file>
>   </welcome-file-list>
>
>   <!-- 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>
>
>
****************************************************************************
> ****
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <!DOCTYPE struts-config PUBLIC
>           "-//Apache Software Foundation//DTD Struts Configuration
1.0//EN"
>           "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
>
> <struts-config>
>
>   <data-sources/>
>
>   <!-- ========== Form Bean Definitions
> =================================== -->
>   <form-beans>
>
>     <!-- Logon form bean -->
>     <form-bean      name="listDirForm"
>
> type="com.covia.struts.actionforms.ListDirectoryContentsForm"/>
>
>   </form-beans>
>
>   <!-- ========== Global Forward Definitions
> ============================== -->
>   <global-forwards/>
>
>   <!-- ========== Action Mapping Definitions
> ============================== -->
>   <action-mappings>
>
>     <action    path="/listDirectoryContents"
>                type="com.covia.struts.actions.ListDirectoryContentsAction"
>                name="listDirForm"
>               scope="request"
>            validate="false">
>       <forward name="listDirectoryContents"
> path="/listDir.jsp"/>
>         </action>
>   </action-mappings>
>
> </struts-config>



Re: .do mappings not working & bean cannot be read by the JSP

Posted by Maya Muchnik <mm...@pumatech.com>.
Iraklis,

I will try to help you, but maybe I could not, because, I am almost in the
start stage as you are. The first you need to understand HOW struts-example
works, you can find "A Walk tour .." in the example menu. This tour explains
step by step, what involve and how in struts-example. The second COMPARE your
struts-config.xml and the example. How the example is starting - from
<welcome-file-list> file, that is index.jsp. And index.jsp is calling logon.jsp
for logon.do action. And so on.

My point is this - you cannot call
http://localhost:7001/myapp/listDirectoryContents.do
directly from a browser, it must be through some start file. Where is your
"welcome.jsp"?

Your do not have an application resource file, maybe it is OK. Because you do
not want to check anything.

The second, Action class is called by ActionServlet, if the servlet is found
that this action must to be performed according to ActionForm submitted through
a request.

Maya

Iraklis Kourtidis wrote

> How are you gentlemen!! Somebody set up me the bomb.
>
> I have installed Struts OK, and I've even run the 'struts-example'
> application (which means that Struts is working fine with me otherwise.) I'm
> trying to create a small application, but I am having problems.
>
> When I type
> http://localhost:7001/myapp/listDirectoryContents.do
> in the browser, I get a 'page not found'. If I change 'do' to something else
> (such as "foo"), I get a Error 404--Not Found, which means that at least the
> 'action' servlet is called... I am appending my web.xml and
> struts-config.xml: for the life of me I can't spot anything wrong about
> them.
>
> A second problem that I've wasted my youth on is that my action class adds
> an object (bean, if you wish) to the request or session by the following:
>
> HttpSession session = request.getSession();
> session.setAttribute("com.covia.struts.folder_contents", di);
>
> or
> request.setAttribute("com.covia.struts.folder_contents", di);
>
> (I'm saying 'or' because I've tried both.)
>
> In my JSP I've used the following line:
> <logic:iterate id="aFile" name="com.covia.struts.folder_contents"
> property="fileroomFolders" scope="session">
>  ...
>
> to access this bean, but I get a message saying
> <Apr 5, 2001 6:32:56 PM CDT> <Error> <HTTP>
> <[WebAppServletContext(2243896,fileroom_struts)] Root cause of
> ServletException
> javax.servlet.jsp.JspException: Cannot find bean
> com.covia.struts.folder_contents in scope session
>
> Again, I've tried this using both 'session' and 'request' scope.
>
> My understanding has been that the action class gets called first. It places
> whatever it needs on the request/session, and then the JSP file that's
> listed in struts-config.xml as its 'input' runs right afterwards. Did I get
> something wrong?
>
> Infinite thanks to whoever can help me with this! I've already wasted a ton
> of time - to no avail - trying to solve this.
> thanks much,
> Iraklis
>
> ****************************************************************************
> ****
> <?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>
>
>   <!-- 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>
>     <init-param>
>       <param-name>debug</param-name>
>       <param-value>2</param-value>
>     </init-param>
>     <init-param>
>       <param-name>detail</param-name>
>       <param-value>0</param-value>
>     </init-param>
>     <init-param>
>       <param-name>validate</param-name>
>       <param-value>false</param-value>
>     </init-param>
>     <load-on-startup>2</load-on-startup>
>   </servlet>
>
>   <!-- Action Servlet Mapping -->
>   <servlet-mapping>
>     <servlet-name>action</servlet-name>
>     <url-pattern>*.do</url-pattern>
>   </servlet-mapping>
>
>   <!-- The Welcome File List -->
>   <welcome-file-list>
>     <welcome-file>welcome.jsp</welcome-file>
>   </welcome-file-list>
>
>   <!-- 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>
>
> ****************************************************************************
> ****
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <!DOCTYPE struts-config PUBLIC
>           "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
>           "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
>
> <struts-config>
>
>   <data-sources/>
>
>   <!-- ========== Form Bean Definitions
> =================================== -->
>   <form-beans>
>
>     <!-- Logon form bean -->
>     <form-bean      name="listDirForm"
>
> type="com.covia.struts.actionforms.ListDirectoryContentsForm"/>
>
>   </form-beans>
>
>   <!-- ========== Global Forward Definitions
> ============================== -->
>   <global-forwards/>
>
>   <!-- ========== Action Mapping Definitions
> ============================== -->
>   <action-mappings>
>
>     <action    path="/listDirectoryContents"
>                type="com.covia.struts.actions.ListDirectoryContentsAction"
>                name="listDirForm"
>               scope="request"
>            validate="false">
>       <forward name="listDirectoryContents"
> path="/listDir.jsp"/>
>         </action>
>   </action-mappings>
>
> </struts-config>